ImportJava.net.Socket; Public classPortscanextendsThread {Private intMinport; Private intMaxport; PublicPortscan (intMinport,intMaxport) { This. Minport =Minport; This. Maxport =Maxport; } Public voidrun () { for(intI=minport; i<=maxport; i++) { Try{Socket Socket=NewSocket ("127.0.0.1", i); System.out.println (string.valueof (i)+ ": OK"); Socket.close (); } Catch(Exception e) {}}} Public Static voidMain (string[] args) {intMinport = Integer.parseint (args[0]); intMaxport = Integer.parseint (args[1]); intThreadCount = Integer.parseint (args[2]); intPortincrement = ((Maxport-minport + 1)/ThreadCount) + (((maxport-minport + 1)% threadcount) = = 0? 0:1); Portscan[] Portscan=NewPortscan[threadcount]; for(inti=0; i<threadcount; i++) {Portscan[i]=NewPortscan (Minport + portincrement * I, Minport + portincrement + portincrement * i-1); Portscan[i].start (); } }}
Thread Fragment Scan Port