python nmap

Solutions on MaxInterview for python nmap by the best coders in the world

showing results for - "python nmap"
Anya
20 Jul 2016
1pip3 install python-nmap
Luca
29 Nov 2018
1import nmap
2 
3scanner = nmap.PortScanner()
4 
5ip_addr = '127.0.0.1'
6 
7response = input("""\nPlease enter the type of scan you want to run
8                1)SYN ACK Scan
9                2)UDP Scan
10                3)Comprehensive Scan
11                4)Regular Scan
12                5. OS Detection
13                6. Multiple IP inputs
14                7. Ping Scan\n""")
15print("You have selected option: ", response)
16 
17# If user's input is 1, perform a SYN/ACK scan
18if response == '1':
19    print("Nmap Version: ", scanner.nmap_version())
20    # Here, v is used for verbose, which means if selected it will give extra information
21    # 1-1024 means the port number we want to search on
22    #-sS means perform a TCP SYN connect scan, it send the SYN packets to the host
23    scanner.scan(ip_addr,'1-1024', '-v -sS')
24    print(scanner.scaninfo())
25    # state() tells if target is up or down
26    print("Ip Status: ", scanner[ip_addr].state())
27    # all_protocols() tells which protocols are enabled like TCP UDP etc
28    print("protocols:",scanner[ip_addr].all_protocols())
29    print("Open Ports: ", scanner[ip_addr]['tcp'].keys())
30     
31# If user's input is 2, perform a UDP Scan   
32elif response == '2':
33    # Here, v is used for verbose, which means if selected it will give #extra information
34    # 1-1024 means the port number we want to search on
35    #-sU means perform a UDP SYN connect scan, it send the SYN packets to #the host
36    print("Nmap Version: ", scanner.nmap_version())
37    scanner.scan(ip_addr, '1-1024', '-v -sU')
38    print(scanner.scaninfo())
39    # state() tells if target is up or down
40    print("Ip Status: ", scanner[ip_addr].state())
41    # all_protocols() tells which protocols are enabled like TCP UDP etc
42    print("protocols:",scanner[ip_addr].all_protocols())
43    print("Open Ports: ", scanner[ip_addr]['udp'].keys())
44     
45# If user's input is 3, perform a Comprehensive scan
46elif response == '3':
47    print("Nmap Version: ", scanner.nmap_version())
48    # sS for SYN scan, sv probe open ports to determine what service and version they are running on
49    # O determine OS type, A tells Nmap to make an effort in identifying the target OS
50    scanner.scan(ip_addr, '1-1024', '-v -sS -sV -sC -A -O')
51    print(scanner.scaninfo())
52    print("Ip Status: ", scanner[ip_addr].state())
53    print(scanner[ip_addr].all_protocols())
54    print("Open Ports: ", scanner[ip_addr]['tcp'].keys())
55     
56# If user's input is 4, perform a Regular Scan
57elif response == '4':
58    # Works on default arguments
59    scanner.scan(ip_addr)
60    print(scanner.scaninfo())
61    print("Ip Status: ", scanner[ip_addr].state())
62    print(scanner[ip_addr].all_protocols())
63    print("Open Ports: ", scanner[ip_addr]['tcp'].keys())
64     
65elif response == '5':
66    print(scanner.scan("127.0.0.1", arguments="-O")['scan']['127.0.0.1']['osmatch'][1])
67 
68elif response == '6':
69    ip_addr = input()
70    print("Nmap Version: ", scanner.nmap_version())
71    # Here, v is used for verbose, which means if selected it will give extra information
72    # 1-1024 means the port number we want to search on
73    #-sS means perform a TCP SYN connect scan, it send the SYN packets to the host
74    scanner.scan(ip_addr,'1-1024', '-v -sS')
75    print(scanner.scaninfo())
76    # state() tells if target is up or down
77    print("Ip Status: ", scanner[ip_addr].state())
78    # all_protocols() tells which protocols are enabled like TCP UDP etc
79    print("protocols:",scanner[ip_addr].all_protocols())
80    print("Open Ports: ", scanner[ip_addr]['tcp'].keys())
81     
82elif response == '7': 
83    scanner.scan(hosts='192.168.1.0/24', arguments='-n -sP -PE -PA21,23,80,3389')
84    hosts_list = [(x, scanner[x]['status']['state']) for x in scanner.all_hosts()]
85    for host, status in hosts_list:
86        print('{0}:{1}'.format(host, status))
87     
88else:
89    print("Please choose a number from the options above")
90
queries leading to this page
how to use python nmapnmap pypiimport nmap pythonhow to get the nmap version in pythonrun nmap in pythonnmap module pythonpydondocs nmap onlinbpython script nmap listingpython nmap 5bpyhton nmappython nmap documentationnmap python for windowshow to use nmap in python nmap python examplenmap pythonnmap python scriptnmap module in python 3pip instal nmappython nmap docspython nmap attributespython nmap librarypython nmap official documentationpython nmap downloadnmap pnnmap with pythonnmap python projectshow to install python nmap library in linuxhow to print nmap in pythonimport nmappython program to run nmapnmap scan pythonnmap port scanner pythonpython nmap packagenmap i pythonnmap pypython nmap scanpython nmapnmap in pythonos scan nmap pythonnmap library pythonnmap python doucmentationpip3 install python nmapnmap command pythonpython nmap pnpip nmapnmap python documentationhow to import python nmapnmap python modulepython nmap 2021nmap python library docspython documentation nmappython 3 nmapnm scaninfonmap api pythonwhat is nmap module called in pythonnmap3 install in pythonmap in python3nmap install pythonpython3 nmapnmap library in pythonpip nmap3nmap module in pythonnmap module python 3build nmap with pythonpython nmap python3nmappytho nmapnmap all hosts pythonhow to print the version of nmap in pythonhow to use nmap with pythonnmap python docsget nmap version using python scriptnmap portscannerasynchow to format output from python nmapscan open ports python nmappython module nmap3nmap for pythonuse nmap with pythonpip install python nmapnmap python3how to work with nmap command in pythonpython nmap exampleuse nmap in python without installingnmap python module documentationpython nmadpython and nmappython nmap documentationnmap python librarypython nmap osnmap pyinstall nmap windows 10 pythonhow to import nmap in pythonpython nmap package downloadnmap scan pypython nmap downloadusing nmap in pythonnmap portscanner python installpython nmap modulepython script for nmap scannmap pypi to get all ips on a networkpython nmap installnmap python apipython nmap