欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

Java类库判断两台机器之间网络是否可达,java类库,Java类库判断两台机器

来源: javaer 分享于  点击 473 次 点评:18

Java类库判断两台机器之间网络是否可达,java类库,Java类库判断两台机器


Java类库判断两台机器之间网络是否可达,常用ping方法来实现。```javaimport java.net.InetAddress;

public class Test {

public static void main(String[] args) {    String IP = "10.1.11.225";    if (Test.ping(IP))        System.out.println("SUCCESS - ping " + IP + " with no interface specified");    else        System.out.println("FAILURE - ping " + IP + " with no interface specified");}/** *  * @param host 主机地址 *  * @return boolean * */public static boolean ping(String host) {    String $host = host;    try {        InetAddress address = null;        if ($host != null && $host.trim().length() > 0) {            address = InetAddress.getByName($host);        }        if (address != null) {        } else {            System.out.println($host + " is unrecongized");        }        if (address.isReachable(5000))            return true;    } catch (Exception e) {        e.printStackTrace();    }    return false;}

}```

相关栏目:

用户点评