Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if server port is open from Android

Tags:

android

port

ping

I am trying to connect to a my remote server from my Android device. How do I check if a specific port on my server is open? Eg. how to check if port 80 is open on my server 11.11.11.11?

Currently, I am using InetAddress to ping if the host is reachable but this does not tell me if the port 80 is open.

Current Code

boolean isAvailable = false;
try {
    isAvailable = InetAddress.getByName("11.11.11.11").isReachable(2000);
    if (isAvailable == true) {
       //host is reachable
       doSomething();
    }
} catch (Exception e) {

}
like image 406
newbie Avatar asked Nov 12 '11 15:11

newbie


People also ask

How do I check open ports on Android?

From the Google Play store install a network tool utility like "IP Tools" app. From the App menu, choose Port ScannerEnter the destination DNS/hostname/IP address of the server hosting the EveryonePrint Mobile Gateway and the port to test, ie port 9444 for the Mobile Gateway TCP port. Verify that the port is available.

How do you check if a port is open on a device?

Type "Network Utility" in the search field and select Network Utility. Select Port Scan, enter an IP address or hostname in the text field, and specify a port range. Click Scan to begin the test. If a TCP port is open, it will be displayed here.

How do I check open ports on a server?

Let's see how : * To display all open ports, open command prompt (Start -> Run -> Cmd), type netstat and press Enter. * To list all listening ports, use netstat -an |find /i listening command. * To find specified open port, use find switch.

Do Android phones have open ports?

A University of Michigan study found 410 Android apps in the Google Play store with open ports. Those 410 apps can be exploited in 956 different ways.


1 Answers

Create a Socket that will check that the given ip with particular port could be connected or not.

public static boolean isPortOpen(final String ip, final int port, final int timeout) {

    try {
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress(ip, port), timeout);
        socket.close();
        return true;
    } 

    catch(ConnectException ce){
        ce.printStackTrace();
        return false;
    }

    catch (Exception ex) {
        ex.printStackTrace();
        return false;
    }
}     
like image 92
Himanshu Joshi Avatar answered Oct 06 '22 01:10

Himanshu Joshi