满意答案

给你一个winpcap的示例代码,具体的可以根据自己的需求修改

#include

#include

#include

#define LINE_LEN 16

int main(int argc, char **argv)

{

pcap_if_t *alldevs, *d;

pcap_t *fp;

u_int inum, i=0;

char errbuf[PCAP_ERRBUF_SIZE];

int res;

struct pcap_pkthdr *header;

const u_char *pkt_data;

printf("pktdump_ex: prints the packets of the network using WinPcap.\n");

printf(" Usage: pktdump_ex [-s source]\n\n"

" Examples:\n"

" pktdump_ex -s file.acp\n"

" pktdump_ex -s \\Device\\NPF_{C8736017-F3C3-4373-94AC-9A34B7DAD998}\n\n");

if(argc < 3)

{

printf("\nNo adapter selected: printing the device list:\n");

/* The user didn't provide a packet source: Retrieve the local device list */

if(pcap_findalldevs(&alldevs, errbuf) == -1)

{

fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);

exit(1);

}

/* Print the list */

for(d=alldevs; d; d=d->next)

{

printf("%d. %s\n ", ++i, d->name);

if (d->description)

printf(" (%s)\n", d->description);

else

printf(" (No description available)\n");

}

if (i==0)

{

printf("\nNo interfaces found! Make sure WinPcap is installed.\n");

return -1;

}

printf("Enter the interface number (1-%d):",i);

scanf("%d", &inum);

if (inum < 1 || inum > i)

{

printf("\nInterface number out of range.\n");

/* Free the device list */

pcap_freealldevs(alldevs);

return -1;

}

/* Jump to the selected adapter */

for (d=alldevs, i=0; i< inum-1 ;d=d->next, i++);

/* Open the adapter */

if ((fp = pcap_open_live(d->name, // name of the device

65536, // portion of the packet to capture.

// 65536 grants that the whole packet will be captured on all the MACs.

1, // promiscuous mode (nonzero means promiscuous)

1000, // read timeout

errbuf // error buffer

)) == NULL)

{

fprintf(stderr,"\nError opening adapter\n");

return -1;

}

}

else

{

/* Do not check for the switch type ('-s') */

if ((fp = pcap_open_live(argv[2], // name of the device

65536, // portion of the packet to capture.

// 65536 grants that the whole packet will be captured on all the MACs.

1, // promiscuous mode (nonzero means promiscuous)

1000, // read timeout

errbuf // error buffer

)) == NULL)

{

fprintf(stderr,"\nError opening adapter\n");

return -1;

}

}

/* Read the packets */

while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)

{

if(res == 0)

/* Timeout elapsed */

continue;

/* print pkt timestamp and pkt len */

printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);

/* Print the packet */

for (i=1; (i < header->caplen + 1 ) ; i++)

{

printf("%.2x ", pkt_data[i-1]);

if ( (i % LINE_LEN) == 0) printf("\n");

}

printf("\n\n");

}

if(res == -1)

{

printf("Error reading the packets: %s\n", pcap_geterr(fp));

return -1;

}

pcap_close(fp);

return 0;

}

00分享举报

基于c语言抓包软件程序,C或者C++写的抓包工具。相关推荐

  1. c语言逻辑运用及宏程序编写,基于C语言基础的宏程序编程

    基于C语言基础的宏程序编程 王恒厂,周燕飞,姚裕,吕常奎 (南京航空航天大学工程训练中心,江苏南京211100) 摘 要:用户宏指令编程是FANUC系统所提供的一种先进的编程方法[1],使用变量代替程 ...

  2. c语言程序流程图绘制软件,程序员都是用什么画图工具绘制C语言程序流程图?这个方法你需要知道...

    对于编程初学者来说,很多人都以为程序设计就是单纯的写代码,其实并不是,程序设计是给出解决特定问题程序的过程,是软件构造活动中的重要组成部分,往往以某种程序语言为工具,给出这种语言下的程序,很多人在接到 ...

  3. 基于c语言的组态软件,工业组态软件中CFC语言的设计实现及语言转换的研究-计算机应用技术专业论文.docx...

    工业组态软件中CFC语言的设计实现及语言转换的研究-计算机应用技术专业论文 摘 要 近年来随着 IEC61131-3 国际标准的正式公布与推广,基于此标准的工业自动 化领域的组态软件,经过不断完善已日 ...

  4. 基于go语言结合微信小程序开发的微商城系统

    最近我录制的一门<Golang微信小程序微商城系统原型>,这门免费课程特别适合在校大学生或者刚毕业的大学生,go语言初学者以及想要从事微商城开发项目入门的小伙伴们来学习.在课程当中我不仅仅 ...

  5. 基于c语言流量预警软件,基于Android的手机流量控制软件答案.doc

    基于Android的手机流量控制软件 设计与实现 1 绪论 1.1 手机移动互联网进展 这些年,移动通信和互联网成为当今世界发展最快.市场潜力最大.前景最诱人的两大业务.它们的增长速度都是任何预测家未 ...

  6. 基于C#语言的Robotstudio软件二次开发基础

    目录 一.开发环境配置 二.开发项目创建 三.代码编写 四.运行测试 本文已经首发在个人微信公众号:工业机器人仿真与编程(微信号:IndRobSim),欢迎关注! Robotstudio软件在为仿真人 ...

  7. 基于c语言图像边缘检测的程序,图像边缘检测之拉普拉斯(Laplacian)C++实现

    拉普拉斯算子(Laplacian)可应用到图像边缘检测中.在OpenCV中当kernel大小为3*3时,支持两种kernel算子,分别为: 在OpenCV中默认的计算方式如下,假设有一个5*5的小图像 ...

  8. linux基于此语言的密码,Impost3r:一款针对Linux的密码提取工具

    Impost3r是一款针对Linux平台的密码管理工具,该工具采用C语言开发,可以帮助广大研究人员在渗透测试的过程中,从目标Linux主机中获取各类密码(ssh.su.sudo). 此工具仅限于安全研 ...

  9. AndroidHttpCapture 网络诊断工具 是一款针对于移动流量劫持而开发的手机抓包软件

    AndroidHttpCapture 项目地址:JZ-Darkal/AndroidHttpCapture 简介:AndroidHttpCapture 网络诊断工具 是一款针对于移动流量劫持而开发的手机 ...

最新文章

  1. 基于Android的红外测温设计,基于Android的红外三维重构移动APP设计与实现
  2. python设计模式整理
  3. matlab制作以太网数据接收上位机_Python制作串口通讯上位机
  4. 一个穷人是从什么时候开始有钱的?
  5. 64位linux下的gns3网络模拟器配置
  6. 爬取新笔趣阁排行并保存到mysql_python+selenium爬取微博热搜存入Mysql的实现方法...
  7. oracle更新数据还原,oracle误drop/update操作后的数据恢复测试
  8. linux删除编译中间件,关于linux 里安装编译环境和中间件
  9. 启动凤凰系统出现android,凤凰系统重启后出现蓝屏时的解决方法
  10. 前端学习笔记之页面制作(一)——PS切图
  11. m-TRP transmission for URLLC(draft)
  12. Django连接MySQL8.0报错django.db.utils.OperationalError: (1045, “Access denied for user ‘16066‘@‘localhos
  13. 2016年华为研发出征大会演讲--任正非
  14. sipp 注册脚本测试服务端含(401)注册流程(UAC )
  15. 本周涨粉一倍,我决定再开源一个商超管理系统
  16. 腾讯物联TencentOS tiny上云初探
  17. CC00042.CloudKubernetes——|KuberNetes二进制部署.V20|5台Server|——|kubernetes配置|生产环境关键性配置|
  18. UG后处理—进给速度R模式输出研究
  19. Android 使用RecycleView制作头像堆叠效果
  20. IDEA:更新项目:remote: [31mx-oauth-basic: Incorrect username or password (access token)

热门文章

  1. 什么是 返点、分销、直销、代理、代销
  2. 记录一下使用nodejs爬取双色球历史开奖数据并写入文件过程,仅自己做着玩玩
  3. HDU4466_Triangle
  4. 达梦数据库SQL日志分析工具Dmlog的使用
  5. 地铁供电系统原理图_地铁小百科——带你认识地铁供电系统
  6. 周鸿一传:中国互联网流氓教父的前世今生
  7. python获取视频缩略图_python接收图片变成缩略图
  8. 3. 工作分配问题(回溯法)设有n件工作分配给n个人。。。
  9. 计算机毕设(附源码)JAVA-SSM教务排课管理系统
  10. 纷享销客CRM为虎邦辣酱的第二次增长插上数字化翅膀