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) {
}
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.
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.
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.
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.
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With