标签:style blog io ar color os sp java for
import java.net.Socket; public class portScan extends Thread { private int minPort; private int maxPort; public portScan(int minPort, int maxPort) { this.minPort = minPort; this.maxPort = maxPort; } public void run() { for(int i=minPort; i<=maxPort; i++) { try { Socket socket = new Socket("127.0.0.1", i); System.out.println(String.valueOf(i) + ":ok"); socket.close(); } catch (Exception e) { } } } public static void main(String[] args) { int minPort = Integer.parseInt(args[0]); int maxPort = Integer.parseInt(args[1]); int threadCount = Integer.parseInt(args[2]); int portIncrement = ((maxPort - minPort + 1) / threadCount) + (((maxPort - minPort + 1) % threadCount) == 0 ? 0 : 1); portScan[] portscan = new portScan[threadCount]; for(int i=0; i<threadCount; i++) { portscan[i] = new portScan(minPort + portIncrement * i, minPort + portIncrement + portIncrement * i -1); portscan[i].start(); } } }
标签:style blog io ar color os sp java for
原文地址:http://www.cnblogs.com/starzou/p/4112701.html