這是代碼:
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地址時,它總是為空。
PS:在上面的代碼中,我試圖查看每個埠正在運行的服務。
uj5u.com熱心網友回復:
如果您使用的是 VPN,請將其關閉。這解決了我的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/373659.html
