How do I get the ports that a process is listening on using python? The pid of the process is known.
You can use netstat -lnp, last column will contain pid and process name. In Python you can parse output of this command.
How to obtain ports that a process in listening on?