installation
windows:
pip install python_nma
Linux:
wge t http://xael.org/pages/python-nmap-0.6.1.tar.gz
tar -zxvf python-nmap-0.6.1.tar.gz
cd python-nmap-0.6.1
python setup.py install
use
nm=nmap.PortScanner() #实例化
scan (host, port, args) Method : scan a specific port in a specified manner specified host or network segments
- host: the host or to scan segment, may be a single ip: 192.168.10.10; small range may be a section of the fence: 192.168.10.10-20; may be a large segment: 192.168.10.0/24
- port: Optional, ports to be scanned, a plurality of ports separated by commas, such as: 23, 24
- args: optional parameter to scan mode
import nmap
nm = nmap.PortScanner()
nm.scan('192.168.10.10-100', '22,21','-sV')
也可以这样
nm.scan(hosts='192.168.1.0/24', arguments='-n -sP -PE -PA21,23,80,3389')
command_line () Method: scanning method returns mapped to a particular command line nmap, i.e. nm.scan () command we above, corresponding to a specific command nmap
import nmap
nm = nmap.PortScanner()
nm.scan('192.168.10.10-100', '22,21','-sV')
a=nm.command_line()
print(a)
###########################
nmap -oX - -p 20,21 -sV 192.168.125.134
scaninfo () Method: Returns nmap scanning information, the format of a dictionary
import nmap
nm = nmap.PortScanner()
nm.scan('192.168.10.10-100', '22,21','-sV')
a=nm.scaninfo()
print(a)
###########################
{'tcp': {'services': '20-21', 'method': 'syn'}}
all_hosts () method: nmap scan returns a list of hosts, a list type format
import nmap
nm = nmap.PortScanner()
nm.scan('192.168.10.10-12', '22,21','-sV')
####################################################
['192.168.10.10','192.168.10.11','192.168.10.12']