Code
#!/usr/bin/env python
#coding=utf-8
import pcap
import dpkt
import os
fp = open(r'c:\url.txt','ab')
pc = pcap.pcap()
b = 'tcp port 80'
pc.setfilter(b)
for ts,pkt in pc:
# print `dpkt.ethernet.Ethernet(pkt)`
Eth = dpkt.ethernet.Ethernet(pkt)
length = Eth.data.len
# print type(length)
if length > 48:
content = str(`Eth.data.data.data`)
if 'GET' in content:
url = content.split()[1]
fp.write(url+'\r\n')
fp.flush()
# print '--------------------------------------------------'
# print str(`Eth.data.data.data`)
# print str(`Eth.data.data.data`).split()[1]
# print '--------------------------------------------------'
fp.close() 这个代码是主实现部分,可以封装起来用
---------------------------------------------------------------------------
低调的python小子
当梦想照进现实 幸福近在咫尺
[jpg]http://ip.ipwind.cn/msn.png[/jpg]