import java.net.*;
import java.io.*;
import java.util.*;
class TCPThread extends Thread {
private String host = null;
private int threadnum = 0;
public TCPThread(String name, String host, int threadnum) {
super(name);
this.host = host;
this.threadnum = threadnum;
}
public void run() {
//此类实现客户端套接字(也可以就叫“套接字”)。套接字是两台机器之间的通信端点。
Socket theTCPsocket;
//此类表示互联网协议 (IP) 地址。
InetAddress hostAddress;
/*
getName()方法三Thread类的一个方法定义如下
public final String getName() {
return String.valueOf(name);
}
*/
System.out.println("Thread " + getName() + " now is created and running");
try {
/*
public static InetAddress[] getAllByName(String\u00A0host)
throws UnknownHostException
在给定主机名的情况下,
根据系统上配置的名称服务返回其 IP 地址所组成的数组。*/
hostAddress = InetAddress.getByName(host);
for(int i = threadnum;i < 1399;i += 60) {
System.out.println("Thread " + getName() + " is Scanning port:" + i);
try {
/*
Socket类的一个带参数的构造函数
public Socket(InetAddress\u00A0address,
int\u00A0port)
throws IOException创建一个流套接字并将其连接到指定 IP 地址的指定端口号。
参数:address - IP 地址。
port - 端口号。
*/
theTCPsocket = new Socket(hostAddress,i);
System.out.println("Thread " + getName() + " find The TCP port " + i + " of " + host + " is open");
switch(i) {
case 21:
System.out.println("(maybe there is a FTP server is running)");
break;
case 23:
System.out.println("(maybe there is a TELNET server is running)");
break;
case 25:
System.out.println("(maybe there is a SMTP server is running)");
break;
case 80:
System.out.println("(maybe there is a HTTP server is running)");
break;
case 110:
System.out.println("(maybe there is a POP server is running)");
break;
case 139:
System.out.println("(This server's netBIOS is reachable)");
break;
}
theTCPsocket.close();
} catch(IOException e) {
}
}
} catch(UnknownHostException e) {
System.err.println("The host:" + host + " is unknown or can not be analysed!");
}
}
}
public class ThreadScan {
public static void main(String[] args) {
String Threadname;
String host;
if(args.length < 1) {
host = "localhost";
} else {
host = args[0];
}
for(int i = 0;i < 60;i++) {
new TCPThread("T" + i,host,i).start();
}
}
}
评论0
最新资源