Linux 中是否有与 Windows InetIsOffline 函数等效的函数?
是否有相当于 InetIsOffline< 的 Linux 函数Windows 中的 /code> 函数
(由
url.dll
提供)可以告诉我系统是否连接到互联网,还是我必须自己编写一些东西?
我问这个问题的原因是我是 Lhogho 的早期采用者。我找到了如何在 Windows 中执行此操作并希望开发一些东西来在 Linux 中提供相同的功能。
Is there a Linux function that is equivalent to the InetIsOffline
function in Windows (provided by url.dll
) that can tell me whether the system is connected to the Internet, or do I have to cook up something myself?
The reason I ask is that I am an early-adopter of Lhogho. I found out how to do this in Windows and wanted to develop something to offer the same functionality in Linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过 D-Bus 与网络管理器通信以查看是否有任何连接,但除此之外没有特定的方法可以执行此操作。甚至 NM 也并不总是准确的。
You can talk to Network Manager over D-Bus to see if anything is connected, but other than that there's no specific way of doing so. And even NM isn't always accurate.
您还可以解析
/proc/net/
下的一些文件,例如/proc/net/if_inet6
或/proc/net/tcp
但为什么你想这么做吗?如果您想检查某个站点是否可访问,只需以编程方式访问它(例如使用 libcurl)。
确实会发生某些网站无法访问而其他网站仍然可以运行的情况。
You could also parse some file under
/proc/net/
such as/proc/net/if_inet6
or/proc/net/tcp
But why do you want to do that? If you want to check that some site is accessible, just access it programmatically (e.g. with libcurl).
And it does happen that some sites are inaccessible and others still work.
这可能意味着“我有默认路由吗?”,或者至少这是一个合理的实现,恕我直言。因此,只需检查路由表(
/proc/net/route
)即可:)。这当然不适用于 IPv6(您需要解析
ipv6_route
),但决定如何处理它很复杂。也许 Wine 源代码或 MSDN 文档可以阐明这个问题。It might mean "do I have a default route?", or at least that would be a reasonable implementation, IMHO. So, just check the routing table (
/proc/net/route
) for it :).That of course will not work with IPv6 (you would need to parse
ipv6_route
), but it's complicated to decide how that should be treated. Maybe Wine source code, or MSDN documentation can shed light on the matter.