我制作了这个数据包嗅探器:
from scapy.all import *
def decode(rawload):
#still trying to figure out how to decode the payload
return str(rawload) #temporary
try:
sniff(iface = "wlan0", filter="host 192.168.1.13", prn=lambda x:x.sprintf("src: %IP.src% (%Ether.src%) receiver: %IP.dst% load: {}".format(decode(x.payload)))) #Error right here
except KeyboardInterrupt:
sys.exit(1)
我得到的错误是“Scapy 异常:格式字符串中的条件错误:[]”
。谁能解释我在这里做错了什么?
最佳答案
.format()
调用的结果对于 Scapy Packet.sprintf()
来说不是有效的字符串(可能是因为 rawload
.
我猜它包含 {
和 }
,它们在 .sprintf()
中用于条件(请参阅 help(Packet .sprintf)
).
我建议您将代码替换为:
prn=lambda pkt: pkt.sprintf("src: %IP.src% (%Ether.src%) receiver: %IP.dst% load: ") + decode(x.payload)
关于python - Scapy异常: Bad condition in format string?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49414928/