问题描述
我正在使用python-3.7构建嗅探工具,当我尝试使用scapy_http模块时遇到了该错误。
它在python-2.x中正常工作。对象类型为packet [scapy.Raw] .load
代码:
#!usr/bin/env python
import scapy.all as scapy
from scapy.layers import http
def sniff(interface):
scapy.sniff(iface=interface,store=False,prn=process_sniffed_packet)
#store=Flase(does not store the output in memory)
#prn= call another function after one packet or any data is sniffed is sniffed
def process_sniffed_packet(packet):
if packet.haslayer(http.HTTPRequest):
if packet.haslayer(scapy.Raw):
load = packet[scapy.Raw].load
if "username" in load:
print(load)
sniff("eth0")
错误:
File "packet_sniffer.py",line 16,in <module>
sniff("eth0")
File "packet_sniffer.py",line 6,in sniff
scapy.sniff(iface=interface,prn=process_sniffed_packet)
File "/usr/local/lib/python3.8/site-packages/scapy/sendrecv.py",line 1036,in sniff
sniffer._run(*args,**kwargs)
File "/usr/local/lib/python3.8/site-packages/scapy/sendrecv.py",line 989,in _run
session.on_packet_received(p)
File "/usr/local/lib/python3.8/site-packages/scapy/sessions.py",line 82,in on_packet_received
result = self.prn(pkt)
File "packet_sniffer.py",line 14,in process_sniffed_packet
if "username" in load:
****TypeError: a bytes-like object is required,not 'str'****
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)