QnA_J
QnA_J

Reputation: 151

How can I know which ports are open on my android device and how to close them?

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

Answers (3)

aboujanane
aboujanane

Reputation: 101

  1. Create a wifi hotspot on your phone
  2. Connect your computer to the hotspot
  3. use ipconfig or ifconfig to know the gateway IP adresse ( ie: your phone's IP adress )
  4. Download nmap : http://nmap.org/
  5. Use the nmap command : nmap -sS -Pn -p- your_phone_ip_adress

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.)


  • PS : For UDP ports use: nmap -sU -Pn -p- your_phone_ip_adress

Upvotes: 10

Prakash
Prakash

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

Chris Stratton
Chris Stratton

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

Related Questions