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()

使用说明

Python3 小工具-ARP扫描

开始程序

Python3 小工具-ARP扫描

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

上一篇:防火墙脚本设计


下一篇:DAY 10冲击蓝桥杯——Python基础10python 循环语句