我正在尝试用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<--
任何帮助将不胜感激! 谢谢!
答案 0 :(得分:0)
在OsX-Box上打印“http_layer”:
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
on Embedded:“无”