如何测试远程系统是否可以访问

编程入门 行业动态 更新时间:2024-10-27 20:32:21
本文介绍了如何测试远程系统是否可以访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想测试使用Java是否可以访问远程系统,或者换句话说使用Java发送ping".该功能应封装在具有布尔值的方法中,例如

I want to test whether a remote system is reachable using Java or in other words "send a ping" using Java. This functionality should be encapsulated in a method with boolean value, for example

public boolean isReachable(String ip) { // what to do :-) }

我已经测试了Java Process类,但是由于使用OutputBuffers进行复杂的输出处理,因此我认为这不是最好的方法.

I've tested the Java Process class, but I don't think that it is the best way to do this, because of the complex output handling with OutputBuffers.

Process proc = Runtime.getRuntime().exec("ping " + ip);

另一种可能性是创建一个Socket Connection并处理抛出的异常,但是如果远程系统是一个裸"的Unix系统,则另一端可能没有Socket :-)另外,我希望能够在无法访问远程系统时设置超时.

Another possibility would be creating a Socket Connection and handle thrown exceptions, but if the remote system is a "naked" unix system, there might be no Socket on the other side :-) Additionally, I'd like to be able to set a timeout, when a remote system is not reachable.

那我该怎么办呢?谢谢!

So how could I do this? Thank you!

推荐答案

InetAddress.getByName(ip).isReachable(timeout);

更多推荐

如何测试远程系统是否可以访问

本文发布于:2023-11-16 18:57:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606944.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   系统

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!