Saturday, May 8, 2010

NIS Port Scanning

import java.net.*;
import java.io.*;
class Port
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String host;
int start,end,avail,unavail,i;
Socket sk;
avail=0;
unavail=0;
System.out.println("Enter the host name : ");
host=br.readLine();
System.out.println("Enter the starting port no : ");
start=Integer.parseInt(br.readLine());
System.out.println("Enter the ending port no : ");
end=Integer.parseInt(br.readLine());
for(i=start;i<=end;i++)
{
System.out.print("Port No. " + i);
try
{
sk=new Socket(host,i);
System.out.println(" : Available");
avail++;
}
catch(Exception E)
{
System.out.println(" : Unavailable");
unavail++;
}
}
System.out.println("Total available port : " + avail);
System.out.println("Total unavailable port : " + unavail);
}
}

No comments: