"python": Two methods of ARP scripting
The first is the use of the Arping tool:
#!/usr/bin/env pythonimport subprocessimport sysimport redef arping (IPAddress="192.168.1.1"): P= subprocess. Popen ("/usr/sbin/arping-c 2%s"% IPAddress, Shell =True, stdout=subprocess. PIPE) out=p.stdout.read () result= out. Split () forIteminchResult:if ":" inchItem:print Itemif__name__ = ="__main__": ifLen (SYS.ARGV) >1: forIpinchsys.argv[1:]: Print"arping", IP arping (IP)Else: arping ()
This approach relies on the tools of a particular platform, and the overall use of a system call.
The second is the use of scapy, which enables platform-agnostic
#!/usr/bin/env python fromscapy Import srp,ether,arp,confimport sysdef arping (iprange="192.168.1.1/24"): Conf.verb=0Ans,unans= SRP (Enter (dst="Ff:ff:ff:ff:ff:ff")/arp (pdst=iprange), timeout=2) Collection= [] forSND, RCVinchAns:result= rcv.sprintf (r"%arp.psrc%%ether.src%"). Split () collection.append (Result)returnCollectionif__name__ = ="__main__": ifLen (SYS.ARGV) >1: forIpinchsys.argv[1:]: Print"arping", IP print arping (IP)Else: Print arping ()
"python": Two methods of ARP scripting