我是一个新的编程以及python,我试图使用下面的代码来嗅探http数据包,我得到了下面的错误,我知道我可以使用.encode()方法,而不是尝试将该列表转换成字节存储在变量中。
我得到了下面的错误,我知道我可以使用.encode()方法,而不是尝试将该列表转换为字节存储在一个变量中。
只是想了解我的列表 关键字 能否将其转换为字节。
类型错误:'str'对象不能被解释为integ。
我的代码
#!/bin/python3
import scapy.all as scapy
from scapy.layers import http
def sniff(interface):
scapy.sniff(iface=interface, store=False, prn=process_sniffed_packets)
def process_sniffed_packets(packet):
if packet.haslayer(http.HTTPRequest):
if packet.haslayer(scapy.Raw):
load = (packet[scapy.Raw].load)
keywords = ["usr", "username", "uname", "pwd", "pass", "password"]
keyword_b = bytes(keywords)
for eachword in keyword_b:
if eachword in load:
print(load)
break
sniff(eth0)
完全追溯
root@kali:~/python_course_zaid/Writing a Packet Sniffer# ./packet_sniffer.py
Traceback (most recent call last):
File "./packet_sniffer.py", line 24, in <module>
sniff("eth0")
File "./packet_sniffer.py", line 7, in sniff
scapy.sniff(iface=interface, store=False, prn=process_sniffed_packets)
File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 972, in sniff
sniffer._run(*args, **kwargs)
File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 925, in _run
session.on_packet_received(p)
File "/usr/lib/python3/dist-packages/scapy/sessions.py", line 47, in on_packet_received
result = self.prn(pkt)
File "./packet_sniffer.py", line 14, in process_sniffed_packets
keyword_b = bytes(keywords)
TypeError: 'str' object cannot be interpreted as an integer
我知道下面的代码工作
keywords = ["usr", "username", "uname", "pwd", "pass", "password"]
for eachword in keywords:
if eachword.encode() in load:
print(load)
break