我正在尝试在带有scapy lib的Linux Embedded 上编写一个小python脚本。在我的 OsX 或 Linux 盒子上,我做这样的事情没有任何问题:
from scapy.all import IP, sniff
from scapy.layers import http
import urllib, re
def process_tcp_packet(packet):
http_layer = packet.getlayer(http.HTTPRequest)
ip_layer = packet.getlayer(IP)
url = str('{1[Path]}'.format(ip_layer.fields, http_layer.fields))
if url:
url = urllib.unquote(url).decode('utf8')
print re.findall(r'(https?://S+lh1)', url)
sniff(filter="tcp and host hostexample.com", prn=process_tcp_packet)
Scapy 文件夹如下所示:
enter code here
/scapy
__init__.py
all.py
...
/layers
__init__.py
http.py
dhcp.py
...
当我启动脚本时,似乎导入了所有模块,但以下行:
url = str('{1[Path]}'.format(ip_layer.fields, http_layer.fields))
返回错误:
AttributeError: 'NoneType' object has no attribute 'fields'
-->End of Python script error report<--
任何帮助将不胜感激!谢谢!
"print http_layer"在 OsX-Box 上:
GET
PATH: someurl....
Http-Version: HTTP/1.1
Host: hostexample.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:37.0) Gecko/20100101 Firefox/37.0
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://hostexample/someurl
Connection: keep-alive
嵌入:"无"