Friday, May 2, 2008

How to write Port Scaner using Java

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;
}

0 Comments:

 

blogger templates 3 columns | Make Money Online