Created
October 11, 2021 03:24
-
-
Save jasimmonsv/05d49a3b7c51243ed08fec799cee784a to your computer and use it in GitHub Desktop.
Get ip, mac address and associated IP addr from pcap file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!#/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