icmp广播报获取局域网主机IP
from scapy.all import *
import random
import threading
def scan(sip,dip):
pkt = Ether(dst="ff:ff:ff:ff:ff:ff")/IP(tos=0x04,ttl=64,proto="icmp",id=random.randint(1,65525),src=sip,dst = dip)/ICMP()/UDP(sport=53,dport=53)
res=srp1(pkt,timeout=2,retry=0,verbose=False)
if res:
if res[ICMP].type==0:
print ('[+]IP:主机%s echo-reply.MAC:%s'%(res[IP].src,res[Ether].src))
if _name_ =='_main_':
sip=get_if_addr("eth0")
for i in range(1,255):
dip="192.168.9."+str(i)
t=threading.Thread(target=scan,args=(sip,dip,))
t.start()