For example, in Android, the PID of a process 1234 is using ports 2222,2223,2224. Now I have a PID 1234. I was wondering how to find out port numbers 2222, 2223, 2224 which the process is using?

I have tried using netstat -anp just as the way in Linux, but that didn't work. netstat -anp in ADB shell has the same effect as just netstat, which is without any command arguments.

up vote 6 down vote accepted

You can either use busybox netstat -pt or cat /proc/1234/net/tcp

  • Thank you so much – user1960407 Jan 9 '13 at 11:33
  • This assumes that busybox is installed. – Ken Sharp Oct 12 '15 at 1:11
  • @Alex cat /proc/1234/net/tcp lists all the tcp sockets on the system, not just the sockets opened by process 1234. – Arpit Aggarwal Dec 13 '16 at 18:40

Try to check my github repository, https://github.com/LipiLee/netstat.

I updated toolbox's netstat in Android source code(https://android.googlesource.com/platform/system/core/+/master/toolbox/netstat.c).

UPDATE: The toolbox's netstat was replaced with toybox's netstat in Android M version. So the netstat in toolbox was removed in the Android source tree.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.