This is the code:
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']))
When I use 127.0.0.1, the code works fine and nmScan.all_hosts()
is not empty, but when I check other ip addresses, it always is empty.
P.S: In the code above, I'm trying to see what service each port is running.
CodePudding user response:
If you're using a VPN, turn it off. This solved my problem.