转载自:
未测试,回头研究研究。
用python+scapy写的,只要双击.py文件即可,扫描当地局域网的主机MAC地址,并把结果写入文档保存。
代码如下:用到注册表。(运行前保证scapy安装成功)
#!/usr/bin/env python#coding=utf-8import sys
import timeimport _winregfrom scapy import srp,Ether,ARP,conf key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{0E184877-D910-4877-B4C2-04F487B6DBB7}")value,type = _winreg.QueryValueEx(key,"DhcpDefaultGateway") f=file('MAC_list.txt','a')scan_time=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())f.write('\n'+scan_time+'\n')f.write('\n'+"The Default Gateway of your host is :"+value[0]+'\n'+'\n')ipscan=value[0].encode('gbk')+'/24'conf.verb = 0
ans,unans = srp(Ether(dst="FF:FF:FF:FF:FF:FF")/ARP(pdst=ipscan),timeout = 2)f.write("------ MAC ------ & ----IP-----"+'\n'+'\n')num=0for snd,rcv in ans: list_mac=rcv.sprintf("%Ether.src% & %ARP.psrc%") f.write(list_mac+'\n') num +=1f.write('\n'+'total : '+str(num)+' computers'+'\n')
f.close()
结果类似于: