Package: inmap
Introductioninmap is a python library which helps in using nmap port scanner. It allows to easilly manipulate nmap scan results and will be a perfect
tool for systems administrators who want to automatize scanning task and reports.Supported Python VersionsPython 3.4+Installing nmap scannerinmap requires the nmap scanner :https://nmap.org/download.htmlDebian based system:sudo apt-get install nmapRed Hat based system:yum install nmapArchLinux:pacman -S nmapOpenSuse:yast2 -i nmapMac OS X:brew install nmapInstall inmap packageIf you havepip3on your system, you can simply install or upgrade the Python bindings:pip3 install inmapAlternately, you can download the source distribution fromPyPI(e.g. inmap-1.2.4.tar.gz), unarchive it, and run:python setup.py installExample 0: Port Scanningimportinmapscan=inmap.ScanController()host=inmap.HostModel()port=inmap.PortModel()scan.scan_ports(host='scantest.nmap.org',ports='0-200')scan.scan_ports(host='scantest.nmap.org',ports='22')# You can use the udp and|or pn optionscan.scan_ports(host="scantest.nmap.org",ports='80',udp=True,pn=True)# Fetch results# =============# for port infos the possible arguments are :  ip_address - port - proto - state - service -versionresults=port.select()# Orresults=port.select(state='open')results=port.select(port=80)results=port.select(ip_address="10.10.10.5")# and so on# Display results# ===============print(results)# if we have a single line of resultprints(results['ip_address'])prints(results['port'])prints(results['proto'])prints(results['state'])prints(results['service'])prints(results['version'])# for version info see the next example# for many resultsprint(results[0]['port'])print(results[1]['service'])# Orforresultinresults:print(result['ip_address'],' - ',result['port'],' - ',result['proto'],' - ',result['state'],' - ',result['service'])Example 1: Port Scanning with their versionimportinmapscan=inmap.ScanController()host=inmap.HostModel()port=inmap.PortModel()scan.scan_version_port(host="scantest.nmap.org",ports='0-200')# orscan.scan_version_port(host="scantest.nmap.org",ports='80')# You can use the udp and|or pn optionscan.scan_version_port(host="scantest.nmap.org",ports='80',udp=True,pn=True)# For fetch and displaying results, see the example 0Example 2: scan the 10 most portsimportinmapscan=inmap.ScanController()host=inmap.HostModel()port=inmap.PortModel()scan.scan_most_ports(host='scantest.nmap.org')# Or scan the 20 most portsscan.scan_most_ports(host='10.10.10.3',number=20)# You can use the udp and|or pn optionscan.scan_most_ports(host='10.10.10.3',number=20,udp=True,pn=True)# For fetch and displaying results, see the example 0Example 3: all information that we can have about this host : OS Detection, Port Scanning …importinmapscan=inmap.ScanController()host=inmap.HostModel()port=inmap.PortModel()# Take more time and need root privilegescan.scan_all(host='scantest.nmap.org')# You can use the udp and|or pn optionscan.scan_most_ports(host='10.10.10.3',udp=True,pn=True)# Or scan the 20 most portsscan.scan_most_ports(host='10.10.10.3',number=20)# You can use the udp and|or pn optionscan.scan_most_ports(host='10.10.10.3',number=20,udp=True,pn=True)# Fetch results# =============# for host infos the possible arguments are :# ip_address, mac_address, hostname, os_family, os_cpe, os_details, device_type, info_host, info_cpe, info_os, network_distanceresults=host.select()# Orresults=host.select(state='Up')# state : Up | Downresults=host.select(ip_address="10.10.10.5")results=host.select(mac_address="08:00:27:D3:EB:F1")results=host.select(hostname="scantest.nmap.org")# and so on, for port infos the possible arguments are :  ip_address - port - proto - state - service -version# Display results# ===============print(results)# if we have a single line of resultprints(results['ip_address'])prints(results['mac_address'])prints(results['hostname'])prints(results['state'])prints(results['os_details'])prints(results['network_distance'])# for version info see the next example# for many resultsprint(results[0]['state'])print(results[1]['ip_address'])print(results[1]['network_distance'])print(results[1]['os_family'])# Orforresultinresults:print(result['ip_address'],' - ',result['mac_address'],' - ',result['hostname'],' - ',result['os_family'])# For fetch and displaying port results, see the example 0Use The Source Luke!View source code online:official:https://github.com/aalouane/inmap