1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| from scapy.all import * import optparse import threading import os def scan(ipt): arppkt=Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ipt) res=srp1(arppkt,timeout=0.5,verbose=0) res_list = [] if res: res_list.append(res.psrc) res_list.append(res.hwsrc) print(res_list) 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()
|