1

I have this packet sniffer I made:

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)   

And the error I get is "Scapy Exception: Bad condition in format string: []". Could anyone explain what I'm doing wrong here?

1 Answer 1

1

The result of your .format() call is not a valid string for Scapy Packet.sprintf() (probably because of the content of rawload.

I guess it contains { and }, which are used in .sprintf() for conditions (see help(Packet.sprintf)).

I'd suggest that you replace your code with something like:

prn=lambda pkt: pkt.sprintf("src: %IP.src% (%Ether.src%) receiver: %IP.dst% load: ") + decode(x.payload)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.