编程语言
首页 > 编程语言> > Python3 小工具-ARP扫描

Python3 小工具-ARP扫描

作者:互联网

from scapy.all import *
import optparse
import threading
import os

def scan(ipt):
    pkt=Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ipt)
    res=srp1(pkt,timeout=0.1,verbose=0)
    if res:
        print(ipt,' is online')

def main():
    parser=optparse.OptionParser('%prog'+"-t <target> -f <filename>")
    parser.add_option('-t',dest='target',type='string',help='Target')
    parser.add_option('-f',dest='fil',type='string',help='File')
    (options,args)=parser.parse_args()
    target=options.target
    fil=options.fil

    if(target==None) and (fil==None):
        print('Please input target(-t) or file(-f)')
        exit(0)
    if target:
        iplist=target.split('.')
        ip=iplist[0]+'.'+iplist[1]+'.'+iplist[2]+'.'
        for t in range(1,255):
            ipt=ip+str(t)
            t=threading.Thread(target=scan,args=(ipt,))
            t.start()
    if fil:
        if os.path.exists(fil):
            with open(fil) as f:
                for i in f.readlines():
                    ipt=i.strip('\n')
                    t=threading.Thread(target=scan,args=(ipt,))
                    t.start()
        else:
            print('File is not exists!')
            exit(0)

if __name__=='__main__':
    main()

使用说明

开始程序

github:https://github.com/zmqq/pytools/tree/master/arpscan

标签:ARP,__,target,ff,parser,扫描,Python3,ipt,fil
来源: https://www.cnblogs.com/zmqqq/p/10517156.html