import pcap, dpkt, struct
import binascii

def main():
    a = pcap.pcap()
    a.setfilter('udp portrange 4000-4050')

    try:
        for i,pdata in a:
            p=dpkt.ethernet.Ethernet(pdata)
            src='%d.%d.%d.%d' % tuple(map(ord,list(p.data.src)))
            dst='%d.%d.%d.%d' % tuple(map(ord,list(p.data.dst)))
            sport = p.data.data.sport
            dport = p.data.data.dport
            qq = int( binascii.hexlify(p.data.data.data[7:11]) , 16 )
            print 'QQ: %d, From: %s:%d , To: %s:%d' % (qq,src,sport,dst,dport)

    except Exception,e:

        print '%s' % e

    n = raw_input()


if __name__ == '__main__':
    main()

 

posted on 2013-04-03 11:38  一个人的天空@  阅读(2925)  评论(0编辑  收藏  举报