How do I get the ports that a process is listening on using python? The pid of the process is known.
One thing that wasn't mentioned. Most port applications in python take a command line argument. You can parse /proc/pid/cmdline and parse out the port number. This avoids the large overhead of using ss or netstat on servers with a ton of connections.
How to obtain ports that a process in listening on?