Skip to content

Instantly share code, notes, and snippets.

@v2-dev
Created September 24, 2017 09:24
Show Gist options
  • Save v2-dev/88e77bff5659dd9be481bea05693d6b0 to your computer and use it in GitHub Desktop.
Save v2-dev/88e77bff5659dd9be481bea05693d6b0 to your computer and use it in GitHub Desktop.
find every device connected to the subnet with the pair MAC Address <---> Subnet IP using scapylibrary
#! /usr/bin/env python
# scan-layer2 : arpings a subnet to find every device connected to the subnet
import sys
if len(sys.argv) != 2:
print ("Usage: scan-layer2 \n eg: scan-layer2.py 192.168.1.0/24")
sys.exit(1)
from scapy.all import srp,Ether,ARP,conf
ans,unans=srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=sys.argv[1]),timeout=10)
for snd,rcv in ans:
print(rcv.sprintf(r"%Ether.src% & %ARP.psrc%"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment