更新Winpcap,出提示,求大神告诉这是什么意思?

2024-05-10 22:40

1. 更新Winpcap,出提示,求大神告诉这是什么意思?

存在一个winpcap,并且被别的程序调用了,正在使用,删除不了,建议关闭这个程序,如果不知道是哪个程序的话,重启电脑,或者放弃更新

更新Winpcap,出提示,求大神告诉这是什么意思?

2. 操作系统WIN7旗舰64位,使用VIRTUAL PC装了XP,如何实现不插网线的情况下实现主机与虚拟机互相PING通呢?

在Win7 安装 WinPcap (Windows 虚拟网卡),就可以在不插网线的情况下实现主机与虚拟机互相连接。

3. 请教Linux网络编程高手,网络编程时碰到的若干问题,如何在IP包或广播包接收客户端上计算接收到的IP包长等

同一楼上的,IP包头有长度字段,你把它提取出来就可以了。
另外,在链路层和网络层可以取到ip数据包,在传输层是没有办法取到IP头之类信息的。
在链路层需要使用libpcap(windows下为winpcap)包进行开发
在网络层可以使用原始套接字进行开发。

请教Linux网络编程高手,网络编程时碰到的若干问题,如何在IP包或广播包接收客户端上计算接收到的IP包长等

4. 真机远程桌面连接虚拟机拔掉网线后断开

是的 虽然不要求主机上网,但是要求主机网卡必须处于连接状况,所以你断开网线后主机与虚拟机的网络也就断开了。 
无论任何一种模式 主机都必须处于连接状态!
如果你确实不想联网 可以在主机安装 安装 WinPcap(虚拟网卡)可以解决!
我的回答是真正正确而专业的! 
http://zhidao.baidu.com/question/321176324.html

5. wireshark如何抓包

1) 正确安装wireshark,一般这步没有问题,winpcap由于有截包功能,少数软件会提醒风险。
2) 打开wireshark后正确选择网卡,因为可能有虚拟网卡和当前未使用的网卡(比如无线环境下)
3) 确保想截的包会通过你的网卡,设置混杂模式,即使目的地址不是你的机器,也可以看到。否则就只能用hub或者用镜像口功能保证那些想截的包过网卡了。
4)确保有足够的协议知识来分析截包,能利用一些现成的插件功能解析包。

wireshark如何抓包

6. p2p网卡尚未初始化 请确认曾经设置掌握网卡 怎么解决 大虾们帮帮忙

你下载这个软件就解决了 。“WinPcap”在360软件管家中的装机必备上搜索就能搜到。下载安装他,P2P终结者就能用了。我之前也是这个问题,不过现在解决了。希望采纳~~!!

7. 怎么再增加printf嗅探的内容呀?

2.3 认识winpcap的基本使用

winpcap最主要的功能就是接受数据,但并不妨碍原来数据的传输,比如我们探测到远程的游戏服务器发来一个我们在游戏等级的数据,winpcap只能探测到他,知道他的全部信息,但是无法修改他,如果要修改还需要其他的知识,这里我们先看一个嗅探程序,请好好理解这个程序

#include "pcap.h"
#include 
#include 
#include 
#define BUFFERCOUNT 256
pcap_t *adhandle;
char InterfaceName[256]={0};
typedef struct et_header
{
    unsigned char   eh_dst[6];
    unsigned char   eh_src[6];
    unsigned short eh_type;
}ET_HEADER;


typedef struct _iphdr              //定义IP首部

{

    unsigned char h_verlen;            //4位首部长度,4位IP版本号

    unsigned char tos;               //8位服务类型TOS

    unsigned short total_len;      //16位总长度(字节)

    unsigned short ident;            //16位标识

    unsigned short frag_and_flags; //3位标志位

    unsigned char ttl;              //8位生存时间 TTL

    unsigned char proto;         //8位协议 (TCP, UDP 或其他)

    unsigned short checksum;        //16位IP首部校验和

    unsigned long sourceIP;            //32位源IP地址

    unsigned long destIP;         //32位目的IP地址

}IP_HEADER;


struct                              //定义TCP伪首部

{

        unsigned long saddr;     //源地址

        unsigned long daddr;     //目的地址

        char mbz;

        char ptcl;                   //协议类型

        unsigned short tcpl;     //TCP长度

}PSD_HEADER;


typedef struct _tcphdr             //定义TCP首部

{

    USHORT th_sport;               //16位源端口

    USHORT th_dport;               //16位目的端口

    unsigned int th_seq;         //32位序列号

    unsigned int th_ack;         //32位确认号

    unsigned char th_lenres;        //4位首部长度/6位保留字

    unsigned char th_flag;            //6位标志位

    USHORT th_win;                 //16位窗口大小

    USHORT th_sum;                 //16位校验和

    USHORT th_urp;                 //16位紧急数据偏移量

}TCP_HEADER;


void packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
    IP_HEADER * ipheader; 
    TCP_HEADER * tcp_header; 
ET_HEADER * et_header;
SOCKADDR_IN addr; 
SOCKADDR_IN saddr;
unsigned short iplen; 
unsigned short sport;
int destPort;
int datasize;
int len;
char buf[1024]={0};
et_header=(ET_HEADER *)pkt_data;
ipheader=(IP_HEADER *)(pkt_data+14);
if(ipheader->proto=6)
{
iplen=(ipheader->h_verlen & 0xf)>>2;
tcp_header=(TCP_HEADER *)(ipheader+iplen);  
sport=ntohs(tcp_header->th_sport); 
destPort=ntohs(tcp_header->th_dport);
   addr.sin_addr.S_un.S_addr=ipheader->sourceIP;
saddr.sin_addr.S_un.S_addr=ipheader->destIP;
datasize=tcp_header->th_lenres>>2;
len=ntohs(ipheader->total_len)-iplen-datasize;

if(len>0)
{

   

   memcpy(buf,(BYTE *)tcp_header+datasize,len);
printf("%s(%d)->%s(%d) flag:%d SYN =%x ACK=%x\n data is: %s \n\n ",
   inet_ntoa(*((IN_ADDR *)&(addr.sin_addr))),
   sport,
   inet_ntoa(*((IN_ADDR *)&(saddr.sin_addr))),
   destPort,
   tcp_header->th_flag,
   ntohl(tcp_header->th_seq),
   ntohl(tcp_header->th_ack),
    buf


   );
}
else
{
printf("%s(%d)->%s(%d) flag:%d SYN =%x ACK=%x\n\n ",
   inet_ntoa(*((IN_ADDR *)&(addr.sin_addr))),
   sport,
   inet_ntoa(*((IN_ADDR *)&(saddr.sin_addr))),
   destPort,
   tcp_header->th_flag,
   ntohl(tcp_header->th_seq),
   ntohl(tcp_header->th_ack)


   );
}

}
}
main(int argc, char **argv)
{
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;    
char packet_filter[] = "tcp";
char errbuf[PCAP_ERRBUF_SIZE];

if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
   fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
   exit(1);
}
    

    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("请输入嗅探的编号. 区间 (1-%d):",i);
    scanf("%d", &inum);
    
    if(inum  i)
    {
        printf("\nmandy,请输入嗅探的编号.\n");
        /* Free the device list */
        pcap_freealldevs(alldevs);
        return -1;
    }
  
/* Jump to the selected adapter */
    for(d=alldevs, i=0; inext, i++);
    
     strcpy( InterfaceName, d->name );
/* 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)
        2000,    // 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;
}



//compile the filter

    printf("\n将嗅探%s此网数据\n", d->description);

    /* At this point, we no longer need the device list. Free it */

    pcap_freealldevs(alldevs);
   
pcap_loop(adhandle, 0, packet_handler, NULL);

    pcap_close(adhandle);
    return 0;
}






程序说明

pcap_findalldevs(&alldevs, errbuf) 用于发现本机所有的网络适配器,这些适配器包括路由器,计算机的网卡等,如果有的话将全部列出来, pcap_if_t类型数据格式是:

struct pcap_if {
struct pcap_if *next;
char *name;   /* name to hand to "pcap_open_live()" */
char *description; /* textual description of interface, or NULL */
struct pcap_addr *addresses;
bpf_u_int32 flags; /* PCAP_IF_ interface flags */
};

next域指示了下一个可用网络适配器的数据(如果有的话),name代表这个适配器的名称,正如注释所说,这个参数会在pcap_open_live这个函数里被使用,而pcap_open_live是本程序的一个重点,当我们选择一个网络适配器的时候,可以这样调用

if ((adhandle= pcap_open_live(d->name, // 适配器的名称
        65536,    // 捕捉数据的最大字节数,当设置为65536的时候,捕捉整个数据
                   1,     // 设置捕捉的模式,当设置为1的时候为混杂模式
        2000,    // 超时设置,这个数据尽量设置的大一些
        errbuf    // 当出错的时候,错误信息保存的缓冲区
        )) == NULL)

这里要说的是第三个数值,一般我们都是设置为1,当设置为1代表了你可以监视所有流入本网的数据,这是因为局域网网关在接受到一个数据的时候,会把这个数据发给所有内部网络的用户,而每个用户的电脑核查该数据的目的物理地址,如果和自己的一样,就接受他,否则就不处理,设置为1代表了混杂模式,该模式会把不是自己物理地址的数据也接受过来.试想一下当你设置你网络适配器为混杂模式后,你甚至可查看到你的同事的正在和外界聊什么等,他们在访问什么网页等,在这基础上你可以做很多事情,好了,回到程序,程序一开始列出了所有你的网络适配器,比如我的机器里,列表如下:



这里我知道我的是2(其他几个是我虚拟机的虚拟网卡,这里没用),当我们选择好适配器的索引后,程序将我们的适配器名称保存在变量InterfaceName以备后用

for(d=alldevs, i=0; inext, i++);    
     strcpy( InterfaceName, d->name );
打开适配器,设置监听的方式
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)
        2000,    // read timeout
        errbuf    // error buffer
        )) == NULL)

该函数执行成功后,返回一个该适配器在winpcap里的句柄,我们用pcap_loop函数来处理在接受到数据时的回调函数,看下pcap_loop函数结构

int pcap_loop(pcap_t *, int, pcap_handler, u_char *);

第一个参数就是刚才pcap_open_live返回后数据,第二个为处理数据的回调函数地址,当有数据来临的时候,将自动跳到这个函数执行,第三个参数代表标志位,一般我们设置为NULL就可以了.

好了,以上的部分你了解下就可以,一时没有理解也没关系,你可以把他看成一个嗅探程序的开场白,大部分程序都是这样的开始,死记硬背也行,关键我们来看下这个回调函数

void packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data)

dumpfile:是一个文件的地址,当我们需要把截获的数据存储到文件时使用

header:反映这个数据包长度以及时间等信息

pkt_data:代表具体的数据包首地址,对于我们这个例子而言,它是以太头,ip头,tcp头以及数据乱七八糟在一起的东西,也是我们处理的重点,

  

再来回顾一下这个公式

截获的数据=以太头(14个字节)+ip头+tcp头+data

既然刚开始的14个字节代表了以太头,那么在以太头下方14个字节处自然可以找到ip头的地址

   et_header=(ET_HEADER *)pkt_data;
ipheader=(IP_HEADER *)(pkt_data+14);

在ip头里我们看几个关键位置处的含义

unsigned char h_verlen; 位首部长度,4位IP版本号,这里是一个8个字节的数据,前面4个字节代表版本号,一般是ipv4或者是ipv6,后面4个字节代表ip头的长度,但是这里以双字作为基本单位,也就是说假设这里是8,那么ip头的长度应该是 8*4=32个字

unsigned short total_len;      他代表了从ip头,tcp头,具体数据的这三个块的大小,在建立三次握手的建立连接的时候,这里是不带数据的,对应与公式里,data这部分的长度是为0,我们可以将该数值依次减去ip头长度,tcp头长度从而得到具体数据的长度

unsigned long sourceIP;   32位源IP地址,发送该数据来源地址

unsigned long destIP;      32位目的IP地址,接受带数据的ip地址

代码 iplen=(ipheader->h_verlen & 0xf)>>2;就是首先把版本好数据设为0,得到的数值乘以4(左移2位),而

tcp头的位置=ip头位置+ip头长度,代码 tcp_header=(TCP_HEADER *)(ipheader+iplen);   正是这个意思.得到tcp头后我们看下tcp头关键字段的含义



USHORT th_sport;   发送该数据的来源端口,注意在具体显示时处理为本机的字节顺序,以下目的端口也是

USHORT th_dport;               16位目的端口

unsigned int th_seq;         32位序列号,这个字段在上一个章已经讲过

unsigned int th_ack;        32位确认号

unsigned char th_lenres;        指示了tcp头的长度,与ip头长度一样,这里也是以双字为基本单位的

USHORT th_sum;                 16位校验和,用于检验数据完整性的一个字段,当校验和不正确的时候,一方拒绝接受,我将会详细说这个校验和的计算

ipheader->total_len代表了整个ip数据报文的长度,该数值减去ip头长度以及tcp头长度即可得到数据的长度

datasize=tcp_header->th_lenres>>2;
len=ntohs(ipheader->total_len)-iplen-datasize;

通过对tcp头以及ip头的了解,你应该很快能理解上述的代码,请牢记这些字段的含义

好了这样我们就完成了一个简单嗅探程序,如果你在你机器中已经调试好了winpcap,不妨看看你的机器里目前的网络数据的流量,看看有什么可以研究地方.

怎么再增加printf嗅探的内容呀?