Skip to content
Advertisement

how to turn protocol number to name with python?

the protocol like tcp and udp is all represented by a number.

JavaScript

the above code will return 6.

How I can get the protocol name if I know the protocol number?

Advertisement

Answer

I’m going to say there is almost definitely a better way then this, but all the protocol names (and values) are stored as constants prefixed by "IPPROTO_" so you can create a lookup table by iterating over the values in the module:

JavaScript
Advertisement