<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://m.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)  編輯  收藏 所屬分類: 性能優化

    主站蜘蛛池模板: 久久精品国产亚洲AV不卡| 大陆一级毛片免费视频观看| 亚洲国产精品一区二区第一页免 | 亚洲视频在线观看网站| 久久成人免费播放网站| 久久夜色精品国产亚洲AV动态图| 中文字幕无线码免费人妻| 亚洲午夜久久久久妓女影院| 182tv免费视频在线观看| 久久精品夜色国产亚洲av| 久久久久久AV无码免费网站下载| 亚洲精品福利视频| 久久久久久精品成人免费图片| 久久夜色精品国产噜噜噜亚洲AV | 综合亚洲伊人午夜网| 91视频精品全国免费观看| 亚洲AV无码国产丝袜在线观看| 午夜免费啪视频在线观看| 亚洲国产午夜精品理论片 | 一区二区免费国产在线观看| 亚洲精品成人网站在线观看 | free哆啪啪免费永久| 亚洲av永久无码精品天堂久久| 女人被男人躁的女爽免费视频| 国产亚洲漂亮白嫩美女在线| 中文字幕第13亚洲另类| 嫩草影院在线播放www免费观看| 亚洲丰满熟女一区二区v| 国产gav成人免费播放视频| 丝袜捆绑调教视频免费区| 亚洲精品在线视频观看| 国产男女猛烈无遮档免费视频网站| 人与动性xxxxx免费| 精品日韩亚洲AV无码| 免费激情视频网站| 黄色免费在线网站| 亚洲高清中文字幕免费| 亚洲日韩在线观看免费视频| 国产妇乱子伦视频免费| 一级毛片视频免费| 亚洲制服在线观看|