Reputation: 3
I have problems with my router when downloading through steam and other programs, such as the internet losing connection with the router. I cant plug my pc to my router using cable so i made a solution: and the other one \Every X secounds disconect and connect to internet
But the problem is i want to make it more efficient so i would like a command that does this:
:a \Check connection \if connected then goto a \if noconnection disconect and connect to internet
i get problems with check connection command as its does not move on to the if
Please help and thanks for your time
Upvotes: 0
Views: 4169
Reputation: 3
This is what I made:
@echo off
:b
cls
:a
color 0A
ping -n 1 192.168.0.1 | findstr TTL && goto a
ping -n 1 192.168.0.1 | findstr TTL || goto Disconnected
:Disconnected
color 0C
echo.
echo //_No_internet_connection_\\
echo.
echo //_Disconnecting_\\
netsh wlan disconnect
timeout /t 1
netsh wlan connect virginmedia8960851
echo.
echo //_Connecting_\\
echo.
timeout /t 6
goto b
Upvotes: 0
Reputation: 4020
This will ping www.google.com
and if there is a response then goto :a
, if not connected then it will goto :Disconnected
.
The findstr
will look for the TTL
(Time to live) in the ping output. Great little trick that can be applied to multiple situations.
ping -n 1 www.google.com | findstr TTL && goto a
ping -n 1 www.google.com | findstr TTL || goto Disconnected
:a
REM Your connected script here
:Disconnected
REM Your disconnect / reconnect script here
You could also condense this to the below. As the script will continue if it does not findstr TTL
or skip to :a
if it does
ping -n 1 www.google.com | findstr TTL && goto a
REM Your disconnect / reconnect script here
:a
REM Your connected script here
Upvotes: 3