This is source code for port scanner.Very easy to implement.If port is available return true.If port is unavailable return false.
public static boolean PortScanner(String host,int port) throws UnknownHostException
{
Socket worker = null; //makes all the connections
int Port =port; //make port
InetAddress hostAddress; //stores the IP address of the target
boolean status=false;
String Host=host;
hostAddress=InetAddress.getByName(Host);
try
{
worker= new Socket(hostAddress,Port);
status=true;
}
catch(java.io.IOException e)
{
status=false;
}
finally
{
try
{
worker.close();
}
catch(java.io.IOException e){}
catch(NullPointerException e){}
}
return status;
}
public static boolean PortScanner(String host,int port) throws UnknownHostException
{
Socket worker = null; //makes all the connections
int Port =port; //make port
InetAddress hostAddress; //stores the IP address of the target
boolean status=false;
String Host=host;
hostAddress=InetAddress.getByName(Host);
try
{
worker= new Socket(hostAddress,Port);
status=true;
}
catch(java.io.IOException e)
{
status=false;
}
finally
{
try
{
worker.close();
}
catch(java.io.IOException e){}
catch(NullPointerException e){}
}
return status;
}
Comments