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

后端 未结 6 931
野性不改
野性不改 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:21

    Not sure how practical this is.

    How about doing the equivalent of traceroute(tracert on windows) and once you get a success, you can proceed.

    In corporate networks, I've seen ICMP(ping) blocked by admins BUT usually, tracert still works. If you can figure out a quick way to do what tracert does, that should do the trick ?

    Good luck!

提交回复
热议问题