首先要安装python-nmap库,还要安装配置好nmap
实验机器IP:192.168.220.139
端口开放情况
代码
# -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import nmap def NmapScan(ip,port): Nmapscan = nmap.PortScanner(nmap_search_path=(‘nmap‘,r‘C:\Program Files (x86)\Nmap\nmap.exe‘)) Nmapscan.scan(ip,str(port)) state = Nmapscan[ip][‘tcp‘][port][‘state‘] print(‘[*] ‘+ip+‘ tcp/‘+str(port)+‘ ‘+state) if __name__ == ‘__main__‘: NmapScan(‘192.168.220.139‘,445) NmapScan(‘192.168.220.139‘,3389)
nmap.PortScanner()中的nmap_search_path参数后要跟上nmap的绝对路径,才能成功执行
运行结果
filtered为端口被防火墙 IDS/IPS屏蔽,无法确定其状态
原文地址:https://www.cnblogs.com/sch01ar/p/8454723.html
时间: 2024-10-10 21:35:41