1

We are using an special android without possibility to installs app. When I am running netstat I can see that port 1975 is in Listen State. I want to know which process is using this port but without using busybox. Is there a way to do this?

Another question is that why It is not possible to apply netstat or lsof switches while using adb shell? It seems that adb shell is ignoring switches and printing same result. The netstat output is always like this

Govan
  • 2,079
  • 4
  • 31
  • 53

2 Answers2

1

lsof -i is not available for Android.

1.cat /proc/net/tcp

you will get a list of all ports with their processes.

  sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode                                                     
   0: 0100007F:13AD 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 3336108 1 0000000000000000 100 0 0 10 0                   
   1: 0100007F:1f90 00000000:0000 0A 00000000:00000000 00:00000000 00000000 10252        0 3579923 1 0000000000000000 100 0 0 10 0                   

this result shows the '8080' port is using by uid 10252. ( 8080 = 1f90 hex value)

2.cat /data/system/packages.list | grep 10252

will show your the package name of the app.

merlin:/ # cat /data/system/packages.list | grep 10252
com.la391.f6a85e 10252 0 /data/user/0/com.la391.f6a85e default:targetSdkVersion=29 3002,3003 0 1
Siwei
  • 19,858
  • 7
  • 75
  • 95
0

lsof might be useful, try this

lsof -i :port

OR netstat

netstat -atnp | grep port

note: p - shows the pid of linked port

OR ss tool

ss -tanp | grep port
user2760375
  • 2,238
  • 2
  • 22
  • 29
  • thanks for answer. I tried already adb shell lsof -i : port. The problem is that it ignores the switch. there is no difference between adb shell lsof and adb shell lsof -i 1975 – Govan Jul 11 '18 at 15:24
  • did you try netstat with -p option, does it show anything ? – user2760375 Jul 11 '18 at 15:27
  • yes I did. There is no difference between netstat and netstat -p both of them are showing same result – Govan Jul 11 '18 at 15:30
  • try ss also fuser might be useful – user2760375 Jul 11 '18 at 15:33
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/174823/discussion-between-user2760375-and-govan). – user2760375 Jul 11 '18 at 15:43
  • similar question - https://unix.stackexchange.com/questions/97752/how-to-identify-a-process-which-has-no-pid – user2760375 Jul 11 '18 at 15:48
  • As I wrote before main problem is running commands in android adb. When I am doing this then It is not possible to use switches for netstat or lsof. I uploaded the image but stackoverflow is not shoing it yet – Govan Jul 11 '18 at 15:51
  • @Govan then go through this link this one is for android adb - https://stackoverflow.com/questions/14229816/how-to-use-adb-shell-to-find-the-ports-which-a-process-is-using – user2760375 Jul 11 '18 at 15:53
  • Already looked at it. Two problems first one I can not install busybox for first solution. For second one there is no 1234 proc in our Android system so it should be different androids – Govan Jul 11 '18 at 15:55