![在 ubuntu 18.04 中使用 nmcli 检查网络连接时出现问题](https://linux22.com/image/938900/%E5%9C%A8%20ubuntu%2018.04%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20nmcli%20%E6%A3%80%E6%9F%A5%E7%BD%91%E7%BB%9C%E8%BF%9E%E6%8E%A5%E6%97%B6%E5%87%BA%E7%8E%B0%E9%97%AE%E9%A2%98.png)
我在用 ”nmcli 网络连接“命令来了解我的 wifi 连接的连通性。与 wifi 建立连接后,如果我发现它没有互联网连接,那么“nmcli 网络连接“ 展示“有限的”这是很自然的。但是当那个 wifi 连接恢复互联网连接时,如果我运行“nmcli 网络连接“然后我也得到了“有限的”代替“满的”。我重新扫描了网络并等待了几秒钟,然后运行命令,但得到了相同的结果。(即有限)
但如果我通过运行“nmcli 设备 wifi 连接 [SSID] 密码 [wap_key]“然后尝试查看网络连接,然后我得到了“满的”
所以,这意味着每次我想检查网络连接时,我都必须重新连接 wifi(这不是我想要的)。是这样吗?
如果没有,请告诉我合适的方法(linux 命令,不是通过 gui 或不是通过 ping,系统命令更可接受)来检查我的 wifi 是否可以访问互联网。[任何 c/c++ 代码也是可以接受的]
答案1
我认为您只是错过了这个论点check
。这个论点重新检查了连通性。
nmcli networking connectivity check
来自手册页
connectivity [check]
Get network connectivity state. The optional check argument tells NetworkManager to
re-check the connectivity, else the most recent known connectivity state is displayed
without re-checking.
Possible states are:
none
the host is not connected to any network.
portal
the host is behind a captive portal and cannot reach the full Internet.
limited
the host is connected to a network, but it has no access to the Internet.
full
the host is connected to a network and has full access to the Internet.
unknown
the connectivity status cannot be found out.