Reputation: 151
Is there an easy way, to see which ports are open on my Android device and a way to close the open ports?
Upvotes: 15
Views: 84872
Reputation: 101
the open TCP ports will be shown as follow :
65531 closed ports PORT
STATE SERVICE
53/tcp open domain
8187/tcp open unknown
38647/tcp open unknown
42761/tcp open
unknown MAC Address: A4:9A:58:::** (Samsung Electronics Co.)
Upvotes: 10
Reputation: 4617
You can try different network commands through runtime and check the results
// netstat -lptu
// netstat -vat
Process su = Runtime.getRuntime().exec("netstat -vat ");
Upvotes: 0
Reputation: 40407
You can determine the currently open ports by reading the textual /proc pseudo-files such as
/proc/net/tcp
/proc/net/udp
This is basically what a netstat command (where implemented) does - you may wish to find and examine the source of a simple netstat implementation (it should be possible to port such to java)
However, when running as an unprivileged app userid, you will only be able to close sockets belonging to your own process (or by roundabout means involving ptrace or process killing, other processes belonging to your userid). Also note that closing a socket does not necessarily make that port available for immediate re-use.
Upvotes: 6