Skip to content

Instantly share code, notes, and snippets.

@NimishMishra
Created June 30, 2020 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NimishMishra/86e9675433a84b696ac338f6aa8841e6 to your computer and use it in GitHub Desktop.
Save NimishMishra/86e9675433a84b696ac338f6aa8841e6 to your computer and use it in GitHub Desktop.
def callback(packet):
global response
if(packet.haslayer('Ethernet')):
response = response + "Ethernet src: " + str(packet['Ethernet'].src) + "\n"
response = response + "Ethernet dst: " + str(packet['Ethernet'].dst) + "\n"
response = response + "Ethernet type: " + str(packet['Ethernet'].type) + "\n"
if(packet.haslayer('IP')):
response = response + "IP ttl: " +str(packet['IP'].ttl) + "\n"
response = response + "IP src: " +str(packet['IP'].src) + "\n"
response = response + "IP dst: " + str(packet['IP'].dst) + "\n"
if(packet.haslayer('TCP')):
response = response + "TCP sport: " + str(packet['TCP'].sport) + "\n"
response = response + "TCP dport: " +str(packet['TCP'].dport) + "\n"
response = response + "TCP flags: " + str(packet['TCP'].flags) + "\n"
if(packet.haslayer('Raw')):
response = response + "Raw: " + str(hexdump(packet['Raw'].load)) + "\n"
response = response + ("------------------------------\n")
def sniffer(target_ip):
filter_string = "ip host " + target_ip
sniff(count=5, prn=callback, filter= filter_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment