我求解java ping程序,即如何在java中实现ICMP??
谢谢各位的帮忙.
谢谢各位的帮忙.
解决方案 »
- 使用javac的编译问题
- android-ndk编译生成的so库 可以在java工程中调用么
- JAVA传输文件和排列问题
- 用java如何实现图片的平铺效果?
- java下面怎么实现文件(图像文件)的预览? 谢谢!
- log4j里用XMLLayout时出现异常的问题, 有知道的进来坐坐!!!
- 怎样在java程序中显示中文字体,比如在窗口上显示楷体、隶书等字体?
- 编写Bean一般用什么工具?BeanBox从哪里下载?
- 加急!!!
- 属性是对象,通常不new,写getters和setters即可,那么什么情况下必须new呢?
- winzip的问题还是java的中文问题?
- thinking in java 例程中的一个问题
* ping the server
* @param server String
* @param timeout int
* @return boolean
* @throws IOException
*/
public static boolean pingServer(String server,int timeout)
{
BufferedReader in = null;
Runtime r = Runtime.getRuntime(); String pingCommand = "ping " + server + " -n 1 -w " + timeout;
try
{
Process p = r.exec(pingCommand);
if (p == null)
{
return false;
}
in = new BufferedReader(new InputStreamReader(p.
getInputStream()));
String line = null;
while ( (line = in.readLine()) != null)
{
if (line.startsWith("Reply from"))
{
return true;
}
}
in.close();
}
catch (Exception ex)
{
return false;
}
return false;
}