ARP Watcher
With Address Resolution Protocol (ARP), we can find live internal hosts. We can write a script to scan for hosts in a given network with Scapy.
How to do it...
We can write a ARP Watcher with the following steps:
- Create an
arp-scanner.py
file and open it in your editor. - We then have to import the required modules:
from scapy.all import *
- Now declare the variables for the script:
interface = "en0"
ip_rage = "192.168.1.1/24"
broadcastMac = "ff:ff:ff:ff:ff:ff"
- Now we can send ARP packets to all the IPs in the IP range, and get answered and unanswered packets.
- Create the ARP packet as follows:
pkt = Ether(dst=broadcastMac)/ARP(pdst = ip_rage)
The structure of the packet will be as follows:

- Then, send the packet with
srp()
and receive the response:
answered, unanswered = srp(pkt, timeout =2, iface=interface, inter=0.1)
- Next, iterate through all the answered packets and print their MAC and IPs:
for send,recive in ans:
print (recive.sprintf(r"%Ether.src% - %ARP.psrc%"))
- Now, run the script with...