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

标签 python python-3.x byte python-3.6 scapy

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

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/

相关文章:

Python,使用多个列表中的列将新行写入CSV

python - 通过读取多个文件来读取任一列中的值

多个模块之间的Python日志只能在原始文件调用的函数中工作?

python-3.x - 我可以从 Python 代码运行 ffmpeg 并在压缩完成后返回信号吗?

Java从字节数组中获取字符串

python - 按 python 中的第一列(或第二列,否则)对文件进行排序

python - 在 for 循环中使用 string.punctuation 替换字母

python-3.x - 当我执行 "rasa init"错误 : "failed to install native tensorflow runtime"

java - 将字节的十进制值再次转换为字节

c - 如何在运行时将任何类型存储在 void* 中?