nmap pyhton

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

showing results for - "nmap pyhton"
Aitana
03 Nov 2016
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
nmap python docspython nmapnmap pyhton