I have the following piece of code that checks whether port 443 is open in a given host.
import java.net.*;
import java.io.IOException;
public class Scan {
public static void main (String[] args) {
String host="put hostname here";
int port=443;
try{
Socket s = new Socket(host,port);
System.out.println("Can listen on port "+port+
" in host "+host+" is open");
} //end try
catch (IOException ex)
{
//remote host is not listening on port 443
System.out.println("Can not listen on port "+port+
" of host "+host);
} //end catch
}
}
My question is: If port 443 is not open in a certain host, this make my program very slow, as I need to check group of hosts. Is there any way to improve the code to make scanning port 443 faster while maintain reliability at the same time? Is there any ways using java programming to make port scanning other than using sockets ?
Please not that pinging before scan will not help, as the hostnames I have are connected, I only need to check if port 443 is open or closed.