import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
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;
InetAddress hostAddress;
System.out.println("Thread " + getName()
+ " now is created and running");
try {
hostAddress = InetAddress.getByName(host);
for (int i = threadnum; i < 65535; i += 60) {
System.out.println("Thread " + getName() + " is Scanning port:"
+ i);
try {
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 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();
}
}
}
(转)TCP端口扫描程序
最新推荐文章于 2024-02-11 10:54:11 发布