Check whether the remote host can be connected with Java

有人推荐使用java的Runtime.exec()方法来直接调用系统的Ping命令。也有人完成了纯Java实现Ping的程序,使用的是Java的NIO包(native io,高效IO包)。
我个人认为,没有必要用Java再重新写一个Ping命令,因为没有多大意义。更多的人是关心用Java实现ping在应用程序中来测试一个远程主机是否可用。其实自从Java 1.5,java.net包中就实现了ICMP ping的功能。以下我来介绍:
自java 1.5以后,java.net.InetAddress中一个方法:Java代码public boolean isReachable(int timeout) throws IOException
public boolean isReachable(int timeout) throws IOException 它实现了ICMP ECHO REQUEST。
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>