nadzoring.network_base.service_on_port module¶
Service name resolution for port numbers.
- nadzoring.network_base.service_on_port.get_service_on_port(port: int) str[source]¶
Return the service name associated with a given port number.
First queries the system service database via
socket.getservbyport. Falls back to a built-in mapping of common ports when the system lookup fails, and returns"unknown"if the port is not recognised by either.- Parameters:
port – Port number to look up. Expected range is 0-65535.
- Returns:
Lowercase service name (e.g.
"http","ssh"), or"unknown"when the port is not recognised.
Examples
>>> get_service_on_port(80) 'http' >>> get_service_on_port(22) 'ssh' >>> get_service_on_port(9999) 'unknown'