Scapy 异常:格式字符串条件错误?

Scapy Exception: Bad condition in format string?

我有这个包嗅探器:

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 Exception: Bad condition in format string: []"。谁能解释我在这里做错了什么?

您的 .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)