zoukankan      html  css  js  c++  java
  • 从pcap文件中分析出数据包

    import dpkt
    import struct
    import sys,os
    
    f=file(sys.argv[1],"rb")
    pcap=dpkt.pcap.Reader(f)
    
    for ts, buf in pcap:
        eth=dpkt.ethernet.Ethernet(buf)
        ip=eth.data
        tcp=ip.data
    
        if eth.type == dpkt.ethernet.ETH_TYPE_IP:
            src_tuple = map(ord, ip.src)
            print "src ip addr: (%d.%d.%d.%d)" % ((src_tuple[0]), (src_tuple[1]), (src_tuple[2]), (src_tuple[3])),
            dst_tuple = map(ord, ip.dst)
            print "dst ip addr: (%d.%d.%d.%d)" % ((dst_tuple[0]), (dst_tuple[1]), (dst_tuple[2]), (dst_tuple[3]))
    

    使用dpkt库

  • 相关阅读:
    2018CodeM复赛
    poj3683
    bzoj3991
    bzoj2809
    bzoj1001
    bzoj1412
    计蒜之道2018复赛
    HDU2255
    bzoj1010
    bzoj2006
  • 原文地址:https://www.cnblogs.com/long123king/p/3605558.html
Copyright © 2011-2022 走看看