0

So I'm trying to get the source IP of a packet I receive using Scapy, but it just doesn't seem to work. The program crashes as soon as I try to print the IP.

I send this packet

send(IP(dst="10.0.0.12")/UDP(dport=53))

And it's received, I made sure of that, I even printed "Potato" after I received it, and it worked. Now, I try to print the source IP with this

from scapy.all import *
import sys
import time

rcvPkt = sniff(count = 1, filter = "port 53")
print rcvPkt.getlayer(IP).src

But whenever I do that, it says that 'list' object has no attribute 'src'. What do I do?

Jashani
  • 5
  • 1
  • 4

1 Answers1

1

sniff() returns a list-like object containing all of the sniffed packets, but you are treating it like an individual packet. Try this:

>>> print rcvPkt[0].getlayer(IP).src
192.168.42.1
Robᵩ
  • 163,533
  • 20
  • 239
  • 308