用到了python-nmap模块(注意是 python-nmap模块 不是nmap模块 且不要安装nmap模块!!!!)
windows 中还需要下载一个 nmap 软件:
下载地址:
https://pan.baidu.com/s/1rmLLLOiRcp1CBCMuKwCOxw
提取码:0tay
import nmap nm = nmap.PortScanner(nmap_search_path=('nmap',r'D:\nmap-7.70\nmap.exe')) ret = nm.scan(hosts='172.16.3.107') # for i,j in ret.items(): # print(i) # for k,v in j.items(): # print(k,v) print('端口扫描用时间:%s'% ret['nmap']['scanstats']['elapsed']) print('在线主机数量:%s'% ret['nmap']['scanstats']['uphosts']) print('不在线主机数量%s'% ret['nmap']['scanstats']['downhosts']) print('总扫描主机数量%s'% ret['nmap']['scanstats']['totalhosts']) # print(ret['scan']) for i,j in ret['scan'].items(): print('主机IP为:%s 扫描结果如下:%s'%(i,j))
windwos 环境下 要配置PATH路径,要不用不了
nm = nmap.PortScanner(nmap_search_path=('nmap',r'D:\nmap-7.70\nmap.exe'))
D:\nmap-7.70\nmap.exe 是下载软件中的 namp.exe 的路径!