使用netsh wlan connect name="your network_name"
您可以请求连接到WiFi网络,但无法确定您是否已连接。
那么,在Batch中,检查我是否连接到WiFi网络的命令行是什么? (WiFi网络可能有也可能没有网络访问权限。)[它也适用于移动热点]
如果已连接,则应显示YES
,
如果未连接,则应显示NO
,
因为我想根据我得到的结果运行一个循环。
那么有人可以编写好的工作批处理程序!!和c ++(如果可能的话)
我尝试过:
WMIC /node: ”PutYourPCNameHere” path WIN32_NetworkAdapter where (NetConnectionID="Wi-Fi") get NetConnectionStatus
但我们不能放置if循环。所以我不知道如何继续!!
和
@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
但是这无法在移动热点(没有互联网)上工作
答案 0 :(得分:2)
C:\Windows\system32>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:\Windows\system32>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:\Windows\system32>netsh wlan show interfaces | Findstr /c:"Signal" && Echo Online || Echo Offline
Offline
C:\Windows\system32>netsh wlan show interfaces | Findstr /c:"Signal" && Echo Online || Echo Offline
Signal : 93%
Online
&&
和||
是简写if
命令
请在此处查看我的CMD备忘单Command to run a .bat file