Python uses scapy for ARP scanning

Source: Internet
Author: User

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
    1. First, import the relevant modules from Scapy.
    2. Ether ()/arp () constructs the ARP packet.
    3. 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

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.