Linux 检查用户是否已连接到 Internet?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3677257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:29:35  来源:igfitidea点击:

check whether a user connected to the Internet or not?

pascal

提问by Ata

How do you check whether a user is connected to the Internet or not?

您如何检查用户是否已连接到 Internet?

采纳答案by Marco van de Voort

First define internet (e.g. sometimes only certain services are accessable, like when only HTTP traffic through a proxy is allowed).

首先定义互联网(例如,有时只有某些服务可以访问,例如只允许通过代理的 HTTP 流量)。

In general, the only somewhat reliable solution is simply to try and check if the targeted service responds.

一般来说,唯一有点可靠的解决方案就是尝试检查目标服务是否响应。

回答by Mason Wheeler

What flavor of Pascal are you using? You should have some Internet library available. If you want to know if there's a connection available, the easiest way to do that is to see if you can connect to anything. How exactly you do this depends on your internet library, but if I had to do this I'd simply try to ping google.com and see if it succeeds or not.

你用的是什么口味的 Pascal?你应该有一些可用的互联网图书馆。如果您想知道是否有可用的连接,最简单的方法是查看是否可以连接到任何东西。你究竟如何做到这一点取决于你的互联网图书馆,但如果我必须这样做,我只会尝试 ping google.com 看看它是否成功。