【发布时间】:2022-01-10 13:49:22
【问题描述】:
这是代码:
import nmap
# initialize the port scanner
nmScan = nmap.PortScanner()
# scan localhost for ports in range 21-443
nmScan.scan('89.43.3.92', '20-450')
# run a loop to print all the found result about the ports
print(nmScan.all_hosts())
for host in nmScan.all_hosts():
print('Host : %s (%s)' % (host, nmScan[host].hostname()))
print('State : %s' % nmScan[host].state())
for proto in nmScan[host].all_protocols():
print('----------')
print('Protocol : %s' % proto)
lport = nmScan[host][proto].keys()
# lport.sort()
for port in lport:
print ('port : %s\service : %s' % (port, nmScan[host][proto][port]['name']))
当我使用 127.0.0.1 时,代码工作正常,nmScan.all_hosts() 不为空,但是当我检查其他 ip 地址时,它总是为空。
P.S:在上面的代码中,我试图查看每个端口正在运行什么服务。
【问题讨论】:
标签: python security ip host nmap