urnenfeld
urnenfeld

Reputation: 1070

Get tcp/udp protocol name(string) based on port number?

The question could apply to any web oriented language.

As the title says, I would like string based on the port number:

For example:

protocol = get_protocol_name(22)
print protocol

This should print out "ssh". A more verbosed version would make sense:

protocol = get_protocol_name(21, true)
print protocol

Could return print out "File Transfer Protocol".

The function has no complexity, the purpose of the question is not how the code would be, but if there is any implementation already embedded in the languages.

Upvotes: 0

Views: 205

Answers (1)

richflow
richflow

Reputation: 2144

Have a look at python's socket module

>>> import socket
>>> socket.getservbyport(23)
'telnet'

Upvotes: 2

Related Questions