The ARP scan tool written by Python

Source: Internet
Author: User

The source code is as follows:

1Rom Scapy.allImport*2 ImportThreading3 ImportArgparse4 ImportLogging5 ImportRe6 7Logging.getlogger ('Scapy.runtime'). SetLevel (Logging. ERROR)8 9 defparse_ip (targets):Ten     " " One resolves IP segments in 192.168.1.1-254 form, decomposed into IP lists A     " " -_split = Targets.split ('-') -FIRST_IP =_split[0] theIp_split = First_ip.split ('.') -IPDOT4 = range (int (ip_split[3)), int (_split[1]) +1) -Ipaddrs = [ip_split[0]+'.'+ip_split[1]+'.'+ip_split[2]+'.'+STR (P) forPinchIpdot4] -     returnIpaddrs +  - defArp_scan (target_ip): +     " " A ARP scanning via Scapy's SR1 function at     " " -     Try: -Ans = SR1 (ARP (pdst=target_ip), timeout=1,verbose=False) -         ifans: -             returnans -     exceptException: in         Print '[-] Packet error' -Exit (1) to  + defParse_arp (target_ip): -     " " the parse the received ARP reply packet, capture the IP and its corresponding Mac *     " " $Ans =Arp_scan (TARGET_IP)Panax Notoginseng     ifans: -         ifAns.haslayer ('ARP') andans.fields['op'] = = 2: the             Print '[+] ip:%s = mac:%s'% (ans.fields['psrc'],ans.fields['hwsrc']) +  A if __name__=='__main__': theUsage ='python% (Prog) s-t [targets]' +Parser = Argparse. Argumentparser (usage=usage,epilog='The above as a description, good luck! ', description='Description: Specifies an IP or IP segment for ARP scanning.', version='V1.0') -Parser.add_argument ('- T', action='Store', dest='Targets', help='targets is an IP or IP segment, such as 192.168.1.x or 192.168.1.1-254') $  $args =Parser.parse_args () -     ifArgs.targets = =None: - parser.print_help () the     elif( notRe.match (R'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', args.targets)) and  -( notRe.match (R'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}-\d{1,3}$', Args.targets)):Wuyi parser.print_help () the     Else: -Targets =args.targets Wu  -  About     ifRe.match (R'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', targets): $IP =Targets - parse_arp (IP) -     elifRe.match (R'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}-\d{1,3}$', targets): -IPS =parse_ip (Targets) A          forIpinchIPs: +t = Threading. Thread (target=parse_arp,args=(IP,)) theT.start ()

The results of the operation are as follows:

1 python exp2.py-t 192.168.1.1-2542 [+] ip:192.168.1.1 = mac:14:75:90: XX:XX:XX3 [+] ip:192.168.1.111 = mac:c6:36:55: XX:XX:XX4 [+] ip:192.168.1.100 = mac:68:3e:34: XX:XX:XX5 [+] ip:192.168.1.112 = mac:84:38:38: XX:XX:XX6 [+] ip:192.168.1.114 = > mac:6c:8d:c1:xx:xx:xx7 [+] ip:192.168.1.103 = mac:84:38:38: XX:XX:XX8 [+] ip:192.168.1.102 = mac:58:1f:28:xx:xx:xx

The ARP scan tool written by Python

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.