<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 閱讀(382) 評論(0)  編輯  收藏 所屬分類: 性能優化

    主站蜘蛛池模板: 成年在线网站免费观看无广告 | 免费在线观看一区| 三上悠亚亚洲一区高清| 午夜视频免费在线观看| 亚洲综合激情五月色一区| 亚洲免费无码在线| 亚洲高清免费在线观看| 国产成人综合久久精品亚洲| 亚洲精品狼友在线播放| 在线观看AV片永久免费| 本道天堂成在人线av无码免费| 亚洲黄色免费电影| 一本久久综合亚洲鲁鲁五月天| 国产精品视频白浆免费视频| 亚洲av无码专区在线观看亚| 国产∨亚洲V天堂无码久久久| 毛片免费全部播放一级| 两个人看的www高清免费观看| 亚洲不卡中文字幕无码| 亚洲欧洲精品无码AV| 免费一级做a爰片久久毛片潮| 亚洲国产成人精品91久久久| a级毛片无码免费真人久久| 四虎一区二区成人免费影院网址 | j8又粗又长又硬又爽免费视频| 欧洲亚洲国产清在高| 亚洲va在线va天堂va手机| 国产成人免费网站在线观看| a成人毛片免费观看| 一个人看的www免费视频在线观看 一个人免费视频观看在线www | 色噜噜AV亚洲色一区二区| 久草免费手机视频| 美女视频黄是免费的网址| 2020天堂在线亚洲精品专区| 免费一级成人毛片| 国内精品免费在线观看| 99久久婷婷国产综合亚洲| 亚洲色欲久久久综合网东京热| 2015日韩永久免费视频播放| 无人在线观看完整免费版视频 | vvvv99日韩精品亚洲|