lsof print numeric ports

UnixTcpPortsLsof

Unix Problem Overview


How do you get lsof to produce numeric port information instead of attempting to resolve the port to service name?

For example, I want TCP *:http (LISTEN) to give me TCP *:80 (LISTEN) in-fact if at all possible I never want to see another service name in lsof print-out ever again. So if there is a way to make numeric ports the default I would like to understand how to do that as well.

Unix Solutions


Solution 1 - Unix

Run lsof -P.

And make sure the P goes before the i, if you combine the option with -i:

lsof -Pi

According to man lsof, -P inhibits the conversion of port numbers to port names for network files. Inhibiting the conversion may make lsof run a little faster. It is also useful when port name lookup is not working properly."

Solution 2 - Unix

Sometimes handy is:

lsof -Pi

When I tried losf -iP it gave me some trash, so make sure P goes first.


As a side note: lsof -3.14 will provide the same trash, don't try this.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCoder GuyView Question on Stackoverflow
Solution 1 - UnixkwarunekView Answer on Stackoverflow
Solution 2 - UnixprostiView Answer on Stackoverflow