gpt4 book ai didi

ping - 您可以在 Java 中运行真正的 ping 吗?

转载 作者:行者123 更新时间:2023-12-05 03:13:45 28 4
gpt4 key购买 nike

最近几周我做了相当多的研究试图创建一个连接诊断工具,我不太想只检查连接是否可用而是诊断是否存在抖动、数据包丢失等..

到目前为止,Java 似乎不支持真正的 ICMP 请求,并且有一些解决方法,但没有一个能实现我正在尝试做的事情。

有谁知道是否可以构建这种工具,或者我应该开始研究其他选项吗?

最佳答案

InetAdress 似乎在可能的情况下使用 ICMP:

https://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html

看看 public boolean isReachable(int timeout)

Test whether that address is reachable. Best effort is made by the implementation to try to reach the host, but firewalls and server configuration may block requests resulting in a unreachable status while some specific ports may be accessible. A typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtained, otherwise it will try to establish a TCP connection on port 7 (Echo) of the destination host.

您可以在这里找到一个简单的使用示例: How to test if a remote system is reachable或这里 How to ping an IP address

关于ping - 您可以在 Java 中运行真正的 ping 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28968846/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com