summaryrefslogtreecommitdiff
path: root/nmapscanner.py
blob: 75fd6b9ced904d0ae439a228c98299f28a0dc6e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sys
import nmap 
    
def nmscan(hosts,ports):
    nm = nmap.PortScanner() 
    nm.scan(hosts,ports)
    #nm.scan(hosts,arguments=ports) 

    for host in nm.all_hosts():
        print('----------------------------------------------------')
        print('Host : %s (%s)' % (host, nm[host].hostname()))
        print('State : %s' % nm[host].state())
        for proto in nm[host].all_protocols():
            print('----------') 
            print('Protocol : %s' % proto)
    
            lport = nm[host][proto].keys()
            #lport.sort()
            for port in lport:
                print("Port : %s\tState : %s\tService : %s (%s -  %s)" % (port, nm[host][proto][port]['state'], nm[host][proto][port]['name'], nm[host][proto][port]['product'], nm[host][proto][port]['version']))
    
#nmscan("xlinfo.fr","22-443")
#nmscan("xlinfo.fr", "-p22-443 -sV") 

if __name__ == "__main__" :
    try:
        nmscan(sys.argv[1],sys.argv[2])
    except:
        print(f"{sys.argv[0]} demande un hôte et une liste de ports en arguments")