Installation
[[email protected] ~]# yum-y install nmap[[email protected] ~]# pip install Python-nmap
Use
Import Nmap # Imports nmap.py module NM = Nmap. Portscanner () # Get Portscanner object Nm.scan (' 127.0.0.1 ', ' 22-443 ') # Scan host 127.0.0.1 port number 22-443 nm.command_line () # Get command line for scanning : Nmap-ox-P 22-443 127.0.0.1nm.scaninfo () # Gets the information for this scan {' TCP ': {' services ': ' 22-443 ', ' method ': ' Connect '}}nm.all_hosts ( # Get all scanned hosts nm[' 127.0.0.1 '].hostname () # Get 127.0.0.1 hostname nm[' 127.0.0.1 '].hostnames () # Gets the host name of the list format Dict 127.0.0.1 # such as [ {' name ': ' hostname1 ', ' type ': ' PTR '}, {' name ': ' hostname2 ', ' type ': ' User '}]nm[' 127.0.0.1 '].state () # Gets the state of the host 127.0.0.1 ( up|down|unknown|skipped) nm[' 127.0.0.1 ' [' TCP '].keys () # Get all TCP ports nm[' 127.0.0.1 '].all_tcp () # Get all TCP ports (sorted) nm[' 127.0.0.1 '].all_udp () # ibid. nm[' 127.0.0.1 '].all_ip () # ibid. nm[' 127.0.0.1 '].all_sctp () # ibid. nm[' 127.0.0.1 '].has_tcp (22) # Whether it contains 22 port information for host 127.0.0.1 nm[' 127.0.0.1 ' [' TCP '][22] # get all the information for host 127.0.0.1 22 port (TCP) nm[' 127.0.0.1 '].tcp (22) # Get host 127.0 .0.1 22 Port All information nm[' 127.0.0.1 ' [' TCP '][22][' state '] # Gets the status of host 127.0.0.1 22 port (TCP) (Open|closed|filter)
Python-nmap using