我环顾四周,却找不到任何关于这件事的东西。这个问题可能是因为我对Python有点陌生,我希望能在这里得到一些帮助。
我看到了2009年的一篇博文:http://stacksmash.org/2009/09/packet-visualization-with-python/
然而,当我运行它时,我会在Scapy的packet.py的第1129行中得到以下错误
$ python test-image.py
Traceback (most recent call last):
File "test-image.py", line 9, in <module>
if(len(pkt.load) > imgWidth):
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line
192, in __getattr__
fld,v = self.getfield_and_val(attr)
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line
189, in getfield_and_val
return self.payload.getfield_and_val(attr)
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line
189, in getfield_and_val
return self.payload.getfield_and_val(attr)
File "/usr/local/lib/python2.7/dist-packages/scapy/packet.py", line
1125, in getfield_and_val
raise AttributeError(attr)
AttributeError: load这可能是更新的库版本的问题(考虑到这是2009年的博客)还是我在这里遗漏了什么?
发布于 2018-05-07 07:17:10
这对我适用于Python 3.6.4
from PIL import Image
from scapy.all import rdpcap
capture = rdpcap('./capture.pcap')
imgHeight = len(capture)
imgWidth = max(len(packet) for packet in capture)
imgSize = imgWidth, imgHeight
print('Image Size: ', imgSize)
img = Image.new('RGB', imgSize, (255, 255, 255))
for i in range(0, imgHeight):
for j in range(0, len(capture[i])):
color = ord(str(capture[i])[j])
# print('Writing pixel', (j,i), 'with value:', color)
img.im.putpixel((j,i), (0, color, 0))
img.save('./result.png')https://stackoverflow.com/questions/50206852
复制相似问题