2017年国赛答案
from scapy.all import *
import optparse
from threading import *
def sweep(packet):
try:
reply = srp1(packet,timeout=1,verbose=0,iface="eth0")
print 'IP:' + reply.psrc + ' MAC: ' + reply.hwsrc
except :
pass
def main():
parser = optparse.OptionParser('usage%prog '+' -H < target host segment/eg :(172.168.1.)')
parser.add_option('-H',dest='tgtHost',type='string',help='speciffy target h')
(options,args)=parser.parse_args()
host = options.tgtHost
if host == None:
print parser.usage
exit(0)
eth =Ether()
eth.dst="ff:ff:ff:ff:ff:ff"
eth.type=0x0806
arp = ARP()
for n in range(1,254):
arp.pdst= host +str(n)
packet = eth/arp
t= Thread(target=sweep,args=(packet))
t.start()
if name =='main':
main()