Reputation: 55
With this code I can get the hostname, used protocols, ports and states of the ports. How can I also get the service information?
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 = list(nm[host][proto].keys())
lport.sort()
for port in lport:
print('port : %s\tstate : %s' % (port, nm[host][proto][port]['state']))
print('----------')
Upvotes: 1
Views: 1195
Reputation: 55
Okay guys, I know how its done now! Since we use NMAP, nmap can tell us what service is running on what port. You can extract the information with something like that for example:
print('port : %s\tservice : %s' % (port, nm[host][proto][port]['name']))
Upvotes: 0
Reputation: 335
You can get service name by port using getservbyport
function from socket
module, try to do something like that:
>>> import socket
>>> socket.getservbyport(80)
'http'
There are no clear way to get info (or definition) about specific service in python, so try to search about website do that (and provide API to using it with python).
Upvotes: 1