`
zhangzcz1999
  • 浏览: 144413 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

(转)TCP端口扫描程序

阅读更多
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();

		}
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics