说明:
假如不知道局域网内其它设备(手机、电视、电脑等)的ip或者mac地址咋办,可以使用Python/ target=_blank class=infotextkey>Python+nmap 局域网内主机扫描,然后根据扫描的结果分析,设备是什么系统、什么厂商等信息
代码:
import nmap
import sys
import json
def get_lan_host(ip):
nm = nmap.PortScanner()
result = nm.scan(hosts=ip, arguments='-sn -PR')# -sn不进行端口扫描
print ('返回结果:n',json.dumps(result,indent=4,ensure_ascii= False))
n=0
for i,j in result['scan'].items():
try:
mac = j['addresses']['mac']
except Exception as e:
#print (e)
mac = '空'
if j['vendor'] == {}:
vendor = '空'
else:
vendor = list(j['vendor'].values())[0]
n=n+1
print (i,mac,vendor)
print (n)
def mAIn(ip):
test_item = ["主机列表"]
tabal_head = ["IP地址","MAC地址","厂商","操作系统","OS版本"]
a = get_lan_host(ip)
return a
if __name__ == '__main__':
ip = '192.168.0.0/24' # 扫描局域网192.168.0.1到192.168.0.255之前的ip主机
#ip = '192.168.75-77.0/24'
Excel_file_name = '局域网主机扫描测试报告.xls'
all_data = main(ip)
执行:
测试结果: