使用nmap扫描端口
import nmap
scanner = nmap.PortScanner()
target = '192.168.8.121'
scanner.scan(target, arguments='-p-')
for host in scanner.all_hosts():
print(host)
if scanner[host].state() == 'up':
print('Host: %s (%s)' % (host, scanner[host].hostname()))
print('State: %s' % scanner[host].state())
for proto in scanner[host].all_protocols():
print('----------')
print('Protocol: %s' % proto)
lport = scanner[host][proto].keys()
for port in lport:
print ('Port : %s\tState : %s' % (port, scanner[host][proto][port]['state']))