如何检查主机是否无法访问?

发布于 2024-12-25 14:42:12 字数 901 浏览 2 评论 0原文

我正在尝试获取 ping 主机无法访问的情况,因为我分别只获得向上和向下的 (0,1) 值,我如何获得告诉我无法访问 ping 主机的任何条件“2”?

我的代码,

import java.net.InetAddress;

public class PingExample 
{
public static void main(String[] args)
{
try
{
InetAddress address = InetAddress.getByName("172.16.2.0");
// Try to reach the specified address within the timeout
// periode. If during this periode the address cannot be
// reach then the method returns false.
boolean reachable = address.isReachable(10000);
System.out.println("Is host reachable? " + reachable);
} catch (Exception e)
{
e.printStackTrace();
}
}
}

什么是主动状态和被动状态?我怎样才能检查它?


编辑:参见此链接第26页 http://nagios.sourceforge.net/docs/ndoutils/NDOUtils_DB_Model.pdf

统计列描述。我想得到这个结果,因为我已经发布了我的代码,那么我如何获得该列“状态”?请记住,我正在对“n”个主机使用循环。

I am trying to get the unreachable condition of the ping host as I am getting just (0,1) value for up and down respectively, how would I get any condition "2" at which it tell me unreachable ping host?

My code,

import java.net.InetAddress;

public class PingExample 
{
public static void main(String[] args)
{
try
{
InetAddress address = InetAddress.getByName("172.16.2.0");
// Try to reach the specified address within the timeout
// periode. If during this periode the address cannot be
// reach then the method returns false.
boolean reachable = address.isReachable(10000);
System.out.println("Is host reachable? " + reachable);
} catch (Exception e)
{
e.printStackTrace();
}
}
}

What is active and passive state? How can I check it?


Edit: see at this link page 26
http://nagios.sourceforge.net/docs/ndoutils/NDOUtils_DB_Model.pdf

stat column description. I want to get this result as I had posted my code, so how would I get that column "state"? Remember I am using loop for "n" hosts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

開玄 2025-01-01 14:42:12

“Up”表示主机 ping 通“down”表示尝试 ping 但失败,因为系统已关闭,而“无法访问”表示它尝试 ping 但连接未完成,因此它会告诉 ping 主机“已通”或“向下”!

从技术角度来看,这没有任何意义,我怀疑这意味着您尝试做的事情也没有任何意义。

郑重声明:

  • Ping 不涉及建立连接。这是一个简单的请求和响应。发生的情况是发送 ICMP 回显请求数据包,然后您等待几秒钟以查看是否收到 ICMP 回显答复数据包。

  • 如果数据包无法路由,您还可能会收到 ICMP 网络不可达或 ICMP 主机不可达 ...

  • 你也可能什么也得不到。您无法可靠地区分“系统已损坏/关闭”、“数据包被网络丢失”、“数据包被过滤掉”和“系统不存在”。在某些情况下,这些都给您...没有答复。

  • 如今,对 ping 的响应(或无响应)通常是由于防火墙阻止不需要的流量等造成的。

那么这一切意味着不可能可靠地区分“down”和“unreachable”......即使您可以提供具有技术意义的区别解释。

我们还没有讨论有多少信息返回到 Java 应用程序。

"Up" means host pinged "down" means tried to ping but fail because sys is off and "unreachable" means that it tried to ping but connection did not completed so that it would tell either the pinged host is "up" or "down"!

This does not make sense from a technical perspective, and I suspect that means that what you are trying to do doesn't make any sense either.

For the record:

  • Ping doesn't involve making connections. It it is a simple request and response. What happens is that an ICMP Echo Request packet is sent, and you wait for a few seconds to see if you get an ICMP Echo Reply packet.

  • You might also get an ICMP Network Unreachable or an ICMP Host Unreachable ... if the packet cannot be routed.

  • You might also get ... nothing. You can't reliably distinguish between "system is broken / off", "packets are getting lost by the network", "packets are being filtered out" and "system doesn't exist". These all give you ... no reply, in some cases.

  • These days, responses (or non-responses) to pings are often due to firewalls blocking unwanted traffic and the like.

So what this all means that it is not possible to reliably distinguish between "down" and "unreachable" ... even if you could provide an explanation for a distinction that made technical sense.

And we haven't talked about how much of this information makes it back to a Java application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文