Port scanning


import java.net.*;
import java.io.IOException;
import javax.swing.*;
public class Trial
{

public static void main(String args[])
{
  try
  {
   String str=JOptionPane.showInputDialog("Enter the host name");

   InetAddress ia=InetAddress.getByName(str);
  System.out.println("ip address is"+ia);
   for(int i=80;i<130;i++)
   {
    try
      {
       Socket s=new Socket(ia,i);
       System.out.println("port "+i+" is open");
       s.close();
       }
      catch(IOException e)
     {
     System.out.println("port "+i+"is off");
    }
   }
  }
catch(UnknownHostException e)
{ }
 }
}





Leave a Reply