Using netsh wlan connect name="your network_name"
you can request to connect to a WiFi network, but can't be sure whether or not you are connected.
So, in Batch, what would be a command line to check whether or not I am connected to a WiFi network? (The WiFi network may, or may not, have network access.) [It should also work for Mobile-hotspots too]
If Connected, It should display YES
,
If NOT Connected, It should display NO
,
because I want to run a loop depending upon the results I get.
So can someone write good working batch program!! and c++(if possible too)
What I have tried:
WMIC /node: ”PutYourPCNameHere” path WIN32_NetworkAdapter where (NetConnectionID="Wi-Fi") get NetConnectionStatus
but we cant put if loops. So I dont know How to proceed !!
and
@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
but this fails to work over mobile hotspots (without internet)