gpt4 book ai didi

python - Scapy异常: Bad condition in format string?

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:43 25 4
gpt4 key购买 nike

我制作了这个数据包嗅探器:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com