Skip to content

Instantly share code, notes, and snippets.

@jasimmonsv
Created October 11, 2021 03:24
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 jasimmonsv/05d49a3b7c51243ed08fec799cee784a to your computer and use it in GitHub Desktop.
Save jasimmonsv/05d49a3b7c51243ed08fec799cee784a to your computer and use it in GitHub Desktop.
Get ip, mac address and associated IP addr from pcap file
!#/usr/bin/env python
from scapy.all import *
# Read in pcap file
packets = rdpcap("/path/to/packets.pcap")
nonstp = []
for pkt in packets:
# filter out STP packets
if pkt.dst == "01:80:c2:00:00:00":
continue
# filter out IPv6 packets
if pkt.type == 0x86dd:
continue
nonstp.append(pkt)
all_mac = {}
for x in nonstp:
mac = x.src
if x.haslayer(IP):
ip = x.getlayer(IP).src
elif x.haslayer(ARP):
ip = x.getlayer(ARP).psrc
else:
# if something else, print and abort
print(x.layers())
break
all_mac[ip] = mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment