Skip to content

Protocol Mappers

These protocol mappers can be used when you have either the application protocol name or number but need the corresponding value. Something to note is that these mappings are divided up per IP protocol. The reasoning behind this is that the same port number could be tied to two different application protocols depending on the underlying IP protocol. For example, when using UDP, port 13400 is the application protocol doip-disc. Looking at the same port using TCP the application protocol is doip-data.

Here are currently available mappers:

  • DCCP_NAME_TO_NUM - Allows mapping from a known DCCP application protocol name to DCCP application protocol number.

  • DCCP_NUM_TO_NAME - Allows mapping from a known DCCP application protocol name to DCCP application protocol number.

  • PROTO_NAME_TO_NUM - Allows mapping from a known IP protocol name to IP protocol number.

  • PROTO_NUM_TO_NAME - Allows mapping from a known IP protocol number to IP protocol name.

  • SCTP_NAME_TO_NUM - Allows mapping from a known SCTP application protocol name to SCTP application protocol number.

  • SCTP_NUM_TO_NAME - Allows mapping from a known SCTP application protocol number to SCTP application protocol name.

  • TCP_NAME_TO_NUM - Allows mapping from a known TCP application protocol name to TCP application protocol number.

  • TCP_NUM_TO_NAME - Allows mapping from a known TCP application protocol number to TCP application protocol name.

  • UDP_NAME_TO_NUM - Allows mapping from a known UDP application protocol name to UDP application protocol number.

  • UDP_NUM_TO_NAME - Allows mapping from a known UDP application protocol number to UDP application protocol name.

Here are a few examples showing how you would use these in your python code.

from netutils.protocol_mapper import (

    PROTO_NAME_TO_NUM,
    PROTO_NUM_TO_NAME,
    TCP_NAME_TO_NUM,
    TCP_NUM_TO_NAME,
    UDP_NAME_TO_NUM,
    UDP_NUM_TO_NAME,
    SCTP_NAME_TO_NUM,
    SCTP_NUM_TO_NAME,
    DCCP_NAME_TO_NUM,
    DCCP_NUM_TO_NAME,
)

# Get DCCP protocol port from known DCCP application name
LTP_DEEPSPACE_PORT = DCCP_NAME_TO_NUM("ltp-deepspace")
print(LTP_DEEPSPACE_PORT)
# 1113

# Get TCP protocol port from known TCP application name
SSH_PORT = TCP_NAME_TO_NUM["ssh"]
print(SSH_PORT)
# 22

# Get SCTP protocol name from known SCTP application port.
SCTP_PORT_1021_APPLICATION_NAME = SCTP_NUM_TO_NAME[1021]
print(SCTP_PORT_1021_APPLICATION_NAME)
# "exp1"

# Get UDP protocol name from known UDP application port
UDP_PORT_20_APPLICATION_NAME = UDP_NUM_TO_NAME[20]
print(UDP_PORT_20_APPLICATION_NAME)
# "ftp-data

Handling of Duplicate Services

The ports are defined by iana and generated via an autogenerated process, however, there is not a strict name to number mapping provided by iana. Often names are duplicated across multiple port numbers.

Take the below example.

Service Name Port Number Transport Protocol Description
compressnet 2 tcp Management Utility
compressnet 2 udp Management Utility
compressnet 3 tcp Compression Process
compressnet 3 udp Compression Process

As you can see, the service name and port combination is not unique. As such, on the second one, a -secondary is appended to the name to accommodate. The resulting structure looks something like:

    "compressnet": {"port_number": 2, "protocols": ["tcp", "udp"]},
    "compressnet-secondary": {"port_number": 3, "protocols": ["tcp", "udp"]},

This behavior is to be expected.