进公司有一段时间了,基本上在里面不忙的时候就写一些的swing工具,上星期的时候主机换端口了,我们这边没得到消息,TIL比较紧急...写了个东东,去scan一下...猜出来了.=.=...ping 好的话的60000个端口约2-3 分钟左右..
public static void main(String args[]) throws InterruptedException { ExecutorService pool = Executors.newFixedThreadPool(500); long s = System.currentTimeMillis(); final Vector list = new Vector(); final Vector all = new Vector(); int startport = 1 << 10; int endport = 1 << 16; for (int i = 1024; i < endport; i++) { final int port = i; all.add(new Callable() { boolean f=true; public Object call() throws Exception { try { Socket socket = new Socket("localhost", port); list.add(port + ""); } catch (UnknownHostException e) { // TODO Auto-generated catch block f=false; } catch (IOException e) { // TODO Auto-generated catch block f=false; }finally{ if(f) System.out.println("scan port==>"+port); return port; } } }); } System.out.println("scanning..."); try { pool.invokeAll(all); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } for (int i = 0; i < list.size(); i++) { System.out.print(list.get(i) + ","); } System.out.println("scan over..."); long e = System.currentTimeMillis(); System.out.println("exec time==>" + (e - s) + "ms"); }
打印信息: