我想获得ping执行时间并在ping主机后生成字符串 [英] I want to get the ping execution time and result in string after ping host

查看:164
本文介绍了我想获得ping执行时间并在ping主机后生成字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得ping执行时间并在ping主机后生成字符串。我该怎么办?

I want to get the ping execution time and result in string after ping host. How can I do it?

推荐答案

long currentTime = System.currentTimeMillis();
boolean isPinged = InetAddress.getByName(servername).isReachable(2000); // 2 seconds
currentTime = System.currentTimeMillis() - currentTime;
if(isPinged) {
    System.out.println("pinged successfully in "+ currentTime+ "millisecond");
} else {
    System.out.println("PIng failed.");
}

但这只会在Windows系统中使用ICMP ping。

But this will use ICMP ping only in windows system.

这篇关于我想获得ping执行时间并在ping主机后生成字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆