Python-scapy: how to translate port numbers to service names

pythonscapytcp

A TCP layer in Scapy contains source port:

>>> a[TCP].sport
80

Is there a simple way to convert port number to service name? I've seen Scapy has TCP_SERVICES and UDP_SERVICES to translate port number, but

print TCP_SERVICES[80] # fails
print TCP_SERVICES['80'] # fails
print TCP_SERVICES.__getitem__(80) # fails
print TCP_SERVICES['www'] # works, but it's not what i need
80

Someone know how can I map ports to services?

Thank you in advance

Best Solution

Python's socket module will do that:

>>> import socket
>>> socket.getservbyport(80)
'http'
>>> socket.getservbyport(21)
'ftp'
>>> socket.getservbyport(53, 'udp')
'domain'