Reputation: 651
On Linux, suppose we have the PID of some process which is running on the machine. Is it possible to get all the remote ports of all socket pairs this process has? How?
We are able to get the ports which are owned by this process by parsing the outputs of executing netstat -anp | grep PID
, I can do it by getting the IP address of this machine via getifaddrs()
then drag the part after xxx.xxx.xxx.xxx:. But I am not able to know the ip addresses of the other ends which is communicating with target process.
Upvotes: 0
Views: 1009
Reputation: 3128
TCP
Use netstat -n
to show remote addresses and ports.
UDP Note that the above doesn't apply to UDP because UDP doesn't have the concept of "connections", hence cannot have a remote address and port. Instead, each UDP message has a source address and port and is handled by a single socket in the destination process. I'm sure there are other ways, but personally I used wireshark to catch UDP packets. As you may have realized, you won't know the remote address until you actually receive a message.
Upvotes: 1