转载自:http://blog.sina.com.cn/s/blog_4b5039210100gn6k.html
未测试,回头研究研究。
用python+scapy写的,只要双击.py文件即可,扫描当地局域网的主机MAC地址,并把结果写入文档保存。
代码如下:用到注册表。(运行前保证scapy安装成功)
#!/usr/bin/env python
#coding=utf-8
import sys
import time
import _winreg
from scapy import srp,Ether,ARP,conf
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
r"SYSTEMCurrentControlSetServicesTcpipParametersInterfaces{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('
'+scan_time+'
')
f.write('
'+"The Default Gateway of your host is :"+value[0]+'
'+'
')
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-----"+'
'+'
')
num=0
for snd,rcv in ans:
list_mac=rcv.sprintf("%Ether.src% & %ARP.psrc%")
f.write(list_mac+'
')
num +=1
f.write('
'+'total : '+str(num)+' computers'+'
')
f.close()
结果类似于: