import dpkt, pcap
pc = pcap.pcap()
pc.setfilter('tcp')
for ts, pkt in pc:
p = dpkt.ethernet.Ethernet(pkt)
if p.data.__class__.__name__ == 'IP':
ip = '%d.%d.%d.%d' % tuple(map(ord, list(p.data.dst)))
data = p.data.data
if data.__class__.__name__ == 'TCP':
if data.dport == 80 and ip == '192.168.2.50':
print data.data
简单打印出来,没有处理。pc = pcap.pcap()
pc.setfilter('tcp')
for ts, pkt in pc:
p = dpkt.ethernet.Ethernet(pkt)
if p.data.__class__.__name__ == 'IP':
ip = '%d.%d.%d.%d' % tuple(map(ord, list(p.data.dst)))
data = p.data.data
if data.__class__.__name__ == 'TCP':
if data.dport == 80 and ip == '192.168.2.50':
print data.data
需要把数据按帧顺序组合起来。