A. Description
Using the scapy third-party library, write an ARP scan of a network segment to obtain the IP address and MAC address of the active host within that segment.
Two. Analysis and Solutions
- First, import the relevant modules from Scapy.
- Ether ()/arp () constructs the ARP packet.
- SRP1 () sends and receives ARP packets.
The code examples are as follows:
#!/usr/bin/env python# _*_ Coding=utf-8 _*_ fromScapy.allImport*ImportSys,getopt def usage(): Print "Usage:sudo./arpscanner.py" def main(argv): Try: opts, args = Getopt.getopt (argv,"")exceptGetopt. Getopterror:usage () Sys.exit (2) forIpFixinchRange1,254): IP ="192.168.1."+str (ipFix) arppkt = ether (dst="Ff:ff:ff:ff:ff:ff")/arp (Pdst=ip, hwdst="Ff:ff:ff:ff:ff:ff") res = SRP1 (ARPPKT, timeout=1, verbose=0)ifRes:Print "IP:"+ RES.PSRC +"MAC:"+ RES.HWSRCif__name__ = ="__main__": Main (sys.argv[1:])
Three. Running results
Python uses scapy for ARP scanning