2015-10-19 67 views
0

我试图建立一个数据包嗅探器,但每次尝试运行此python我得到一个TypeError一个整数是必需的,当我试图读取数据包的前20个字节。TypeError:缓冲区需要整数

这是给我一个错误代码的一部分:

try: 
while True: 

    #read in a packet 
    raw_buffer = sniffer.recvfrom(65565)[0] 

    #create an IP Header from the first 20 bytes of the buffer 
    ip_header = IP(raw_buffer[0:20]) 

    #print out the protocol that was detected and the hosts 
    print "Protocol: %s %s -> %s" % (ip_header.protocol, ip_header.src_address, ip_header.dst_address) 

回答

0

你假设IP报头是第一个接收缓冲区,但也许事实并非如此。通常情况下,以太网报头位于它之前,因此可能导致IP构造器失败。