如何使用“系统调用”确定Linux上的以太网状态?

发布于 2024-09-25 06:44:04 字数 136 浏览 0 评论 0原文

通常我使用 ping 来确定以太网状态,例如:

ping -c 1 -w 1 <ip_addr>

我们如何使用系统调用来确定以太网状态?我们如何将这个方法嵌入到java代码中呢?

usually I use ping to determine ethernet status, like:

ping -c 1 -w 1 <ip_addr>

how could we use system call to determine ethernet status? and how could we embedded this method in java codes?

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

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

发布评论

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

评论(1

铜锣湾横着走 2024-10-02 06:44:04

ping 不能确定以太网状态;它发送一个数据包并等待响应,因此它用于端到端测试网络。

您当然可以编写自己的 ping,互联网上有很多示例。在 Linux 下,您通常需要成为 root 才能使用所需的套接字类型。

如果您确实只想确定链接是否处于活动状态,请查看以下输出

ip link sh 

ping doesn't determine ethernet status; it sends a packet and waits for a response, so it is used to end-to-end test a network.

You can of course write your own ping, there are plenty of examples on the internet. Under Linux you generally need to be root to use the type of sockets required.

If you do genuinely just want to determine whether the link is active, have a look at the output of

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