"python": Two methods of ARP scripting

Source: Internet
Author: User

"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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.