使用VC++或者MFC编写一个基于winpcap的网络抓包软件

littleqrs 2015-01-15 10:17:33
各位大神!小弟最近在做毕设,真心不会。求各位大神赐教,有没有基于winpcap的网络抓包软件的源代码,实现数据包解析,网络流量分析等功能。小弟参考一下,实在无从下手
...全文
1187 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
cooksa 2015-02-11
  • 打赏
  • 举报
回复
引用 4 楼 cjqpker 的回复:
顺便说一下,这个功能就是数 UDP数据包的个数,要实现你自己的方法,把方法 packet_handler 改写就好了。 运行之前安装一下 WinPcap,另外需要的头文件和lib官网有下载的地方,加载方式不懂得话再问
请问libpcap和winpcap函数名,用法,功能全一样吗?是不是学一种,另一种就会了?
greex 2015-02-11
  • 打赏
  • 举报
回复
下载个ace或boost的socket样例,改下把获取到的数据打印出来就可以了。
假正经的班长 2015-02-11
  • 打赏
  • 举报
回复
引用 8 楼 cooksa 的回复:
[quote=引用 4 楼 cjqpker 的回复:] 顺便说一下,这个功能就是数 UDP数据包的个数,要实现你自己的方法,把方法 packet_handler 改写就好了。 运行之前安装一下 WinPcap,另外需要的头文件和lib官网有下载的地方,加载方式不懂得话再问
请问libpcap和winpcap函数名,用法,功能全一样吗?是不是学一种,另一种就会了?[/quote] 两者应该是一样的,libpcap是linux平台下的,移植到Windows平台下就是Winpcap。我在Windows下写的程序,拿到Linux下重新编译了一下,就能用。
小竹z 2015-01-16
  • 打赏
  • 举报
回复
自己写,将网卡设置为混杂模式,然后就可以接受网卡过来的所有数据包,然后再自己分析~
littleqrs 2015-01-16
  • 打赏
  • 举报
回复
不好意思,我真的不知道怎么下手。我是学自动化的,结果毕设选的是这个。真心哭了。真的不太懂,那个lib下好了,可是不太会加载,大神,求赐教。还有有没有什么资料推荐一下。谢谢
littleqrs 2015-01-16
  • 打赏
  • 举报
回复
恩恩,三克油。我先做做,不会的再请教
luciferisnotsatan 2015-01-15
  • 打赏
  • 举报
回复
http://baike.baidu.com/view/696423.htm
假正经的班长 2015-01-15
  • 打赏
  • 举报
回复
顺便说一下,这个功能就是数 UDP数据包的个数,要实现你自己的方法,把方法 packet_handler 改写就好了。 运行之前安装一下 WinPcap,另外需要的头文件和lib官网有下载的地方,加载方式不懂得话再问
假正经的班长 2015-01-15
  • 打赏
  • 举报
回复
winpcap的接口常用的也没几个。这个例子是我从实例代码中改了一下,你可以参考一下

#ifdef _MSC_VER
/*
 * we do not want the warnings about the old deprecated and unsecure CRT functions
 * since these examples can be compiled under *nix as well
 */
#define _CRT_SECURE_NO_WARNINGS
#endif

#include "pcap.h"

/* prototype of the packet handler */
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);

int main()
{
	pcap_if_t *alldevs;
	pcap_if_t *d;
	int inum;
	int i=0;
	pcap_t *adhandle;
	char errbuf[PCAP_ERRBUF_SIZE];
	
	/* Retrieve the device list */
	if(pcap_findalldevs(&alldevs, errbuf) == -1)
	{
		fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
		exit(1);
	}
	
	/* Print the list */
	for(d=alldevs; d; d=d->next)
	{
		printf("%d. %s", ++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 device */
	/* Open the adapter */
	if ((adhandle= 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)
							 100,			// read timeout
							 errbuf			// error buffer
							 )) == NULL)
	{
		fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
		/* Free the device list */
		pcap_freealldevs(alldevs);
		return -1;
	}
	
	printf("\nlistening on %s...\n", d->description);
	
	/* At this point, we don't need any more the device list. Free it */
	pcap_freealldevs(alldevs);
	
	/* start the capture */
	pcap_loop(adhandle, 0, packet_handler, NULL);
	
	pcap_close(adhandle);
	return 0;
}


/* Callback function invoked by libpcap for every incoming packet */
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
	static int nCount = 0;
	if (pkt_data[12] == 0x08 && pkt_data[13] == 0x00)
	{
		printf("接收到第%5d个UDP协议数据包\n", nCount++);
	}
	
}


fly_dragon_fly 2015-01-15
  • 打赏
  • 举报
回复
这个不是开源的吗

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧