<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    paulwong

    端口掃描程序

    If you need 200ms for each of the 65536 ports (in the worst case, a firewall is blocking everything, thus making you hit your timeout for every single port), the maths is pretty simple: you need 13k seconds, or about 3 hours and a half.

    You have 2 (non-exclusive) options to make it faster:
    • reduce your timeout
    • paralellize your code
    Since the operation is I/O bound (in contrast to CPU bound -- that is, you spend time waiting for I/O, and not for some huge calculation to complete), you can use many, many threads. Try starting with 20. They would divide the 3 hours and a half among them, so the maximum expected time is about 10 minutes. Just remember that this will put pressure on the other side, ie, the scanned host will see huge network activity with "unreasonable" or "strange" patterns, making the scan extremely easy to detect.

    The easiest way (ie, with minimal changes) is to use the ExecutorService and Future APIs: @import url(http://www.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

    public static Future<Boolean> portIsOpen(final ExecutorService es, final String ip, final int port, final int timeout) {
      return es.submit(new Callable<Boolean>() {
          @Override public Boolean call() {
            try {
              Socket socket = new Socket();
              socket.connect(new InetSocketAddress(ip, port), timeout);
              socket.close();
              return true;
            } catch (Exception ex) {
              return false;
            }
          }
       });
    }


    Then, you can do something like:

    public static void main(final String args) {
      final ExecutorService es = Executors.newFixedThreadPool(20);
      final String ip = "127.0.0.1";
      final int timeout = 200;
      final List<Future<Boolean>> futures = new ArrayList<>();
      for (int port = 1; port <= 65535; port++) {
        futures.add(portIsOpen(es, ip, port, timeout));
      }
      es.shutdown();
      int openPorts = 0;
      for (final Future<Boolean> f : futures) {
        if (f.get()) {
          openPorts++;
        }
      }
      System.out.println("There are " + openPorts + " open ports on host " + ip + " (probed with a timeout of " + timeout + "ms)");
    }


    If you need to know which ports are open (and not just how many, as in the above example), you'd need to change the return type of the function to Future<SomethingElse>, where SomethingElse would hold the port and the result of the scan, something like:

    public final class ScanResult {
      private final int port;
      private final boolean isOpen;
      // constructor
      
    // getters
    }


    Then, change Boolean to ScanResult in the first snippet, and return new ScanResult(port, true) or new ScanResult(port, false) instead of just true or false





    posted on 2013-03-14 10:10 paulwong 閱讀(381) 評論(0)  編輯  收藏 所屬分類: 性能優化

    主站蜘蛛池模板: 亚洲免费在线观看视频| 亚洲成在人线aⅴ免费毛片| 一级毛片免费在线播放| 国产亚洲视频在线观看| 亚洲AV无码国产剧情| 青青草国产免费久久久91| xxxx日本免费| 青青草a免费线观a| 噼里啪啦电影在线观看免费高清| 97视频热人人精品免费| 久久久久国色AV免费观看性色| 成人人免费夜夜视频观看| a成人毛片免费观看| 亚洲av永久无码制服河南实里| 亚洲日韩一页精品发布| 久久亚洲综合色一区二区三区| 亚洲gv猛男gv无码男同短文| 亚洲AV无码久久精品成人| 亚洲色四在线视频观看| 亚洲特级aaaaaa毛片| 色偷偷女男人的天堂亚洲网| 亚洲av午夜电影在线观看| 免费看一级高潮毛片| 中文字幕亚洲综合小综合在线| 亚洲一级片在线观看| 无码乱人伦一区二区亚洲一| 久久久无码精品亚洲日韩京东传媒| 亚洲精品无码久久久| 亚洲综合国产一区二区三区| 久久久久亚洲精品美女| 亚洲国产av高清无码| 亚洲妇女无套内射精| 国产精品免费久久久久久久久| 国产亚洲欧美在线观看| 一级毛片免费在线| 午夜影院免费观看| 成人黄页网站免费观看大全| 亚洲精品97久久中文字幕无码| 亚洲AV日韩精品久久久久| 99热亚洲色精品国产88| 男女啪啪免费体验区|