端口扫描程序[JAVA]

 之前BLOG搬过来的东西
  1. import java.net.*;
  2. import java.io.*;
  3. public class Scanner implements Runnable
  4. {
  5.  private InetAddress IPAddress;
  6.  private int Port;
  7.  private Thread allportThread;
  8.  public Scanner(String IPAddress, int port)
  9.  {
  10.   try
  11.   {
  12.    this.IPAddress = this.IPAddress.getByName(IPAddress);
  13.    this.Port = port;
  14.   }
  15.   catch(Exception e)
  16.   {
  17.    System.out.println("The host does not exist.");
  18.   }
  19.  }
  20.  public void run()
  21.  {
  22.   try
  23.   {
  24.    Socket TestPort = new Socket(this.IPAddress, this.Port); //if this port cannot been connected, throw a exception.
  25.    System.out.println(this.Port + ": exist"); //if connected, print out.
  26.   }
  27.   catch(Exception e){}
  28.  }
  29.  public static void main(String[] args)
  30.  {
  31.   String str;
  32.   str =  "TPoI Scanner 1.0 - Network Host Scanner/n";
  33.   str += "Author: T.T (TPoI:http://www.tpoi.net)/n/n";
  34.   str += "Usage: Scanner <options> <Hostname>/n/n";
  35.   str += "<options> List:/n";
  36.   str += "   -allport : scan the status of all the ports of the specified host/n";
  37.   str += "   -port %0 : scan the status of the specified ports(%0) of the specified host/n/n";
  38.   str += "Examples:/n";
  39.   str += "   Scanner -allport www.microsoft.com/n";
  40.   str += "   Scanner -port 80 21.64.34.191";
  41.   if(args.length==0)
  42.   {
  43.    System.out.println(str);
  44.   }
  45.   else
  46.   {   
  47.    args[0] = args[0].toUpperCase().trim();
  48.    char switchArgs = args[0].charAt(1);
  49.    switch(switchArgs)
  50.    {
  51.     case 'A':
  52.     {
  53.      for(int i=1;i<=65535;i++)
  54.      {
  55.       Scanner mainScanner = new Scanner(args[1],i);
  56.       if(mainScanner.allportThread.activeCount()>100)
  57.        mainScanner.run();
  58.       else
  59.       {
  60.        mainScanner.allportThread = new Thread(mainScanner);
  61.        mainScanner.allportThread.start();
  62.       }
  63.      }
  64.      break;
  65.     }
  66.     case 'P':
  67.     { 
  68.      Scanner mainScanner = new Scanner(args[2],java.lang.Integer.parseInt(args[1],10));
  69.      try
  70.      {
  71.       mainScanner.run();
  72.      }
  73.      catch(Exception e)
  74.      {
  75.       System.out.println("parameter error");
  76.      }
  77.      break;
  78.     }
  79.     default:
  80.      System.out.println(str);
  81.    }
  82.   }
  83.  }
  84. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值