This article will cover steps to find used ports (on destination side) by an app on Android using adb command. We will use pixel-2 for this article. But any other android phone can also be used. These steps require Android phone to be rooted.
- Install adb tools on your PC (Mac) and enable developer mode on android phone.
- Root the Android phone. Here are the root steps for pixel-2.
- Connect android phone with Laptop using USP port
- Find the process id (PID) of the app using adb and top.
- Run the following command to see ports opened using adb and lsof (after replacing the 5882 with correct PID for you). This command will ignore the ports in CLOSE_WAIT state.
adb shell "su -c lsof | grep 5882 | egrep 'TCP|UDP' | grep -v CLOSE_WAIT"
- Here is how the outcome looks like for Youtube
- Here we can see that Youtube app has connected to ports 443, 8008, 80 to various servers.
The above steps can be used to debug an app.