What is the quickest way to detect an unreachable host in Java?

后端 未结 6 930
野性不改
野性不改 2021-02-08 01:38

I would like the fastest and most accurate function boolean isReachable(String host, int port) that passes the following JUnit tests under the conditions below. Tim

6条回答
  •  说谎
    说谎 (楼主)
    2021-02-08 02:16

    If you need to do this with a seriously large number of hosts in a very brief period of time, I'd consider using a tool like fping instead- shell out to exec it and parse the output when it comes back. fping runs a large number of parallel queries at once, so you could theoretically check a few thousand hosts in a minute (I think the limit is 4096?)

提交回复
热议问题