我在用 ”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.