I am doing a sniffing of the network and trying to get ip address and port number on every tcp packet.
I used scapy with python and could successfully sniff packets and in a callback function could even print the packet summary. But I would want to do more, like fetching only the IP address of the source and its port number. How can i accomplish it? Below is my code:
#!/usr/bin/evn python
from scapy.all.import.*
def print_summary(pkt):
packet = pkt.summary()
print packet
sniff(filter="tcp",prn=packet_summary)
Please suggest a method to print only the source IP address of every packet.
Thanks.
User2871462 has a terrific answer, I would comment on it but I don't have the required amount of reputation. :) The only thing I would add is that depending on the use case you may want to add the store=0 flag to the sniff call so you're not storing the packets. From the scapy docstring "store: wether to store sniffed packets or discard them".
It is not very difficult. Try this:
Enjoy!