[这个贴子最后由黑色海岸线在 2005/02/22 02:56pm 第 1 次编辑]
/**
* Created by IntelliJ IDEA.
* User: fengzhizi
* Date: 2005-2-7
* Time: 0:28:33
* To change this template use Options | File Templates.
*/
import java.io.*;
import java.net.*;
public class scan {
public static void main(String args[])
{
int Thread_Num=50; //设置默认线程数50
String host="localhost";
int minPort;
int maxPort;
int portNum;
ScanPort sp[]=new ScanPort[Thread_Num];
minPort=Integer.parseInt(args[1]);
maxPort=Integer.parseInt(args[2]);
if(args.length == 3 && minPort=new ScanPort(host,minPort+i,minPort+i,i);
sp.start();
}
}
else
{
int startPort = minPort, endPort = minPort;
int A = portNum / Thread_Num ;
int B = portNum % Thread_Num;
for(int i=0; i=new ScanPort(host,startPort,endPort,i);
sp.start();
}
else
{
System.out.println("b大于50");
}
}
}
try
{
loop:
while(true)
{
for(int i=0; i.isAlive())
continue loop;
break;
}
}
catch(NullPointerException e)
{
System.out.println(e.toString());
}
System.out.println("扫描结束");
}
}
class ScanPort extends Thread
{
//--- 分别定义目标,开始端口,结束端口,线程标记 ---//
private String host;
private int sPort;
private int ePort;
private int tag;
private int i;
//--- 构造函数(重新构造端口) ---//
ScanPort(String h, int sP, int eP, int t)
{
super();
host=h;
sPort=sP;
ePort=eP;
tag=t;
}
public void run()
{
//--- 测试端口是否打开 ---//
for(i=sPort; i<=ePort; i++)
{
try
{
Socket s = new Socket(host, i);
System.out.println("Host:"+host+" Port: "+i+" is Opening."+tag+"线程");
Thread.yield();
}
catch(IOException e)
{
System.out.println("Host:"+host+" Port: "+i+" is Closed."+tag+"线程");
}
}
}
}
|