Python nmap
examples/net/portscan.py
import nmap nm = nmap.PortScanner() nm.scan('127.0.0.1', '20-1024') print(nm.command_line()) for host in nm.all_hosts(): print('----------------------------------------------------') print('Host : {} ({})'.format(host, nm[host].hostname())) print('State : {}'.format(nm[host].state())) for proto in nm[host].all_protocols(): print('----------') print('Protocol : {}'.format(proto)) lport = nm[host][proto].keys() for port in lport: print ('port : {}\tstate : {}'.format(port, nm[host][proto][port]['state']))
nmap -oX - -p 10-1024 -sV 127.0.0.1 ---------------------------------------------------- Host : 127.0.0.1 () State : up ---------- Protocol : tcp port : 21 state : open port : 22 state : open port : 23 state : open