使用批处理,如何确定您是否已连接到WiFi网络
Using Batch, how to determine whether or not you are connected to a WiFi network?
使用netsh wlan connect name="your network_name"
您可以请求连接到WiFi网络,但不能确定您是否已连接。
那么,在批处理中,检查我是否已连接到WiFi网络是什么命令行?(WiFi网络可能会或可能无法访问网络。)[它也适用于移动点孔]
如果连接,则应显示YES
,
如果未连接,则应显示NO
,
因为我想根据得到的结果来运行一个循环。
有人可以编写良好的工作批处理程序!!和C (如果可能的话)
我尝试的是:
WMIC /node: ”PutYourPCNameHere” path WIN32_NetworkAdapter where (NetConnectionID="Wi-Fi") get NetConnectionStatus
,但是我们不能循环。所以我不知道如何继续!
和
@echo off
ECHO Checking connection, please wait...
PING -n 1 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :TRYAGAIN
:TRYAGAIN
ECHO FAILURE!
ECHO Let me try a bit more, please wait...
@echo off
PING -n 3 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS2
IF ERRORLEVEL 1 goto :TRYIP
:TRYIP
ECHO FAILURE!
ECHO Checking DNS...
ECHO Lets try by IP address...
@echo off
ping -n 1 216.239.37.99|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESSDNS
IF ERRORLEVEL 1 goto :TRYROUTER
:TRYROUTER
ECHO FAILURE!
ECHO Lets try pinging the router....
ping -n 2 192.168.1.1|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :ROUTERSUCCESS
IF ERRORLEVEL 1 goto :NETDOWN
:ROUTERSUCCESS
ECHO It appears that you can reach the router, but internet is unreachable.
goto :FAILURE
:NETDOWN
ECHO FAILURE!
ECHO It appears that you having network issues, the router cannot be reached.
goto :FAILURE
:SUCCESSDNS
ECHO It appears that you are having DNS issues.
goto :FAILURE
:SUCCESS
ECHO You have an active Internet connection
pause
goto END
:SUCCESS2
ECHO You have an active internet connection but some packet loss was detected.
pause
goto :END
:FAILURE
ECHO You do not have an active Internet connection
pause
goto :END
:END
但这无法在移动热点(没有互联网)
C:Windowssystem32>netsh wlan show interfaces
There is 1 interface on the system:
Name : Wi-Fi
Description : Realtek RTL8723BE 802.11 b/g/n Wi-Fi Adapter
GUID : 6383a702-c44d-465e-8f5d-e7b3bc52b300
Physical address : 18:4f:32:35:3b:1d
State : connected
SSID : OptusWiFi E5331 0afa
BSSID : d0:7a:b5:8a:0a:fa
Network type : Infrastructure
Radio type : 802.11n
Authentication : WPA2-Personal
Cipher : CCMP
Connection mode : Profile
Channel : 6
Receive rate (Mbps) : 72
Transmit rate (Mbps) : 72
Signal : 93%
Profile : OptusWiFi E5331 0afa
Hosted network status : Not available
C:Windowssystem32>netsh wlan show interfaces
There is 1 interface on the system:
Name : Wi-Fi
Description : Realtek RTL8723BE 802.11 b/g/n Wi-Fi Adapter
GUID : 6383a702-c44d-465e-8f5d-e7b3bc52b300
Physical address : 18:4f:32:35:3b:1d
State : disconnected
Radio status : Hardware On
Software Off
Hosted network status : Not available
是两个状态的输出,连接而未连接。
因此,测试Signal
是否出现在输出中,表示是否连接。
C:Windowssystem32>netsh wlan show interfaces | Findstr /c:"Signal" && Echo Online || Echo Offline
Offline
C:Windowssystem32>netsh wlan show interfaces | Findstr /c:"Signal" && Echo Online || Echo Offline
Signal : 93%
Online
&&
和 ||
是速记if
命令
请参阅我的CMD备忘单。在此处命令运行.bat文件
相关文章:
- 当套接字连接断开时检测C/C++Unix
- 无法在windows上使用mingw将sqlite3与c连接
- 到连接组件算法的问题(递归)
- QTcpSocket在不阻塞GUI的情况下重新连接到服务器
- 无法在C++中建立与MySQL数据库的连接
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 连接 dockerized 模型和 dockerized 数据库时出现"无法 SQLConnect"错误
- 使用 bfs 解决连接组件问题时得到错误的答案
- 在C++的两个字符串中连接以逗号分隔的唯一值
- 无法使用 ESP32 连接家庭 WiFi?
- 在 Windows 问题上连接到企业 WiFi
- 在安卓和PC之间创建Wifi点对点连接
- 如何使用 Windows 本机 Wifi 功能连接到请求网络安全密钥的 Wifi
- 如何在QT或Windows API中连接到无线WIFI网络
- 哪个c/c++库可以用来处理linux的wifi连接
- 如何在带有C / C++的Windows中确定连接的Wifi WLAN接口
- 通过wifi直接连接PC c++与android平板电脑
- QT应用程序——WIFI连接
- 如何使用libqrencode为Wifi连接创建QRcode