I have had a personal internet issue; My main location is out in the boonies, which only allows for cellular high speed. Next choice was satellite, which is plainly never gonna happen.... So, cellular it is.
Now, it works all fine and dandy, but when the area gets flooded with traffic (interstate backed up for instance), the connection seems to timeout and stay unresponsive until I disconnect, then reconnect the cellular adaptor from the cellular data network. Which, in-turn, requires me to disconnect my VPN service (openVPN) before and reconnect it after the cellular disconnect as well.
Over time this has pointed me towards problems with connection handling at my local node. So; how did I remedy this? Same as everything else in my life..... a batch file. If I were working for the cellular provider; I'd fix the actual problem. Till it's fixed, I have this.
They belong in the root of C:\ Yes; Because admin priv is necessary anyways.
Requires Windows Powershell. (Typically built-in to windows)
BETA TEST VERSION Re-arranged some things. Changed disconnect/reconnect as to require only one file for the whole batch. Now there is a powershell script for people with openVPN that properly and cleanly shuts down the connection and application. This is for inactive systems; as there is a "foreground sent" enter key by the powershell script to close a dialogue. The powershell script can be omitted, and your own VPN string inserted in place if you don't use openVPN (see a post comment just a few below the top post for an example). So far tested on Win7 x64 and Win 10 x64.
C:\rebooter.bat
@ECHO OFF
SET OVERALLCOUNT=0
SET FAILEDPINGS=0
SET COUNT1=0
SET COUNT2=0
SET COUNT3=0
SET COUNT4=0
SET COUNT5=0
SET COUNT6=0
SET COUNT7=0
SET C1=47.35.23.146
SET C2=www.google.com
SET C3=www.microsoft.com
SET C4=www.facebook.com
SET C5=www.myspace.com
SET C6=sfbay.craigslist.org
SET C7=garlic.com
SET REBOOTCOUNT=0
GOTO FIRSTSTART
:START
SET /A OVERALLCOUNT=%OVERALLCOUNT%+1
:FIRSTSTART
CLS
ECHO Ping loops since reboot: %OVERALLCOUNT%
ECHO Failed pings since reboot: %FAILEDPINGS%
ECHO Total number of netReboots: %REBOOTCOUNT%
ECHO.
ECHO Total Ping Breakdown:
ECHO.
ECHO %COUNT1% : %C1%
ECHO %COUNT2% : %C2%
ECHO %COUNT3% : %C3%
ECHO %COUNT4% : %C4%
ECHO %COUNT5% : %C5%
ECHO %COUNT6% : %C6%
ECHO %COUNT7% : %C7%
choice /c q /n /t 60 /d q
ping %C1% -n 1 -w 5000
SET /A COUNT1=%COUNT1%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
ping %C2% -n 1 -w 5000
SET /A COUNT2=%COUNT2%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
ping %C3% -n 1 -w 5000
SET /A COUNT3=%COUNT3%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
ping %C4% -n 1 -w 5000
SET /A COUNT4=%COUNT4%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
ping %C5% -n 1 -w 5000
SET /A COUNT5=%COUNT5%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
ping %C6% -n 1 -w 5000
SET /A COUNT6=%COUNT6%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
ping %C7% -n 1 -w 5000
SET /A COUNT=%COUNT7%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
ping %C1% -n 1 -w 5000
SET /A OVERALLCOUNT=%OVERALLCOUNT%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
:JUMP
ECHO Internet connection down, Restarting cellular adaptor...
SET /A REBOOTCOUNT=%REBOOTCOUNT%+1
SET OVERALLCOUNT=0
SET FAILEDPINGS=0
powershell -executionPolicy bypass -file "C:\closeVPN.ps1"
ipconfig /flushdns
netsh interface set interface "Cellular" DISABLED
netsh interface set interface "Cellular" ENABLED
ECHO Restarting VPN Service...
START c:\Progra~1\OpenVPN\bin\openvpn-gui.exe --connect JaredKaragen.ovpn
ECHO VPN Service Started.
choice /c q /n /t 5 /d q
GOTO START
C:\closevpn.ps1
$sig = @"
[DllImport(`"user32.dll`")]
public static extern IntPtr FindWindow(string className, IntPtr useZero);
[DllImport(`"user32.dll`")]
public static extern int SendMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam);
[DllImport(`"user32.dll`")]
public static extern void keybd_event(Byte bVk, Byte bScan, UInt32 dwFlags, UInt32 dwExtraInfo);
[DllImport(`"user32.dll`")]
public static extern int PostMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam);
"@
$win32_methods = Add-Type -MemberDefinition $sig -Name "Win32FindWindow" -Namespace Win32Functions -PassThru
$h = $win32_methods::FindWindow("OpenVPN-GUI", 0)
$win32_methods::PostMessage($h, 0x10, 0, 0)
sleep 1
##### simulate enter key down VK_ENTER = 0xD, scan code = 0x9c
$win32_methods::keybd_event(0xD, 0x9c, 0, 0)
##### simulate enter key up: for this change the flags to KEYEVENTF_KEYUP = 0x2
$win32_methods::keybd_event(0xD, 0x9c, 0x2, 0)
*UPDATED 6/14/2017* Cleaned up code and added counters with display. Updated timer values and streamlined the redundancy.
C:\netWatch.bat
@ECHO OFF
SET OVERALLCOUNT=0
SET FAILEDPINGS=0
SET COUNT1=0
SET COUNT2=0
SET COUNT3=0
SET COUNT4=0
SET COUNT5=0
SET COUNT6=0
SET COUNT7=0
SET C1=10.8.0.1
SET C2=www.google.com
SET C3=www.microsoft.com
SET C4=www.facebook.com
SET C5=www.myspace.com
SET C6=sfbay.craigslist.org
SET C7=garlic.com
SET REBOOTCOUNT=0
GOTO FIRSTSTART
:START
SET /A OVERALLCOUNT=%OVERALLCOUNT%+1
:FIRSTSTART
CLS
ECHO Ping count since reboot: %OVERALLCOUNT%
ECHO Failed pings since reboot: %FAILEDPINGS%
ECHO Total number of netReboots: %REBOOTCOUNT%
ECHO.
ECHO Total Ping Breakdown:
ECHO.
ECHO %COUNT1% : %C1%
ECHO %COUNT2% : %C2%
ECHO %COUNT3% : %C3%
ECHO %COUNT4% : %C4%
ECHO %COUNT5% : %C5%
ECHO %COUNT6% : %C6%
ECHO %COUNT7% : %C7%
choice /c q /n /t 60 /d q
ping %C1% -n 1 -w 1000
SET /A COUNT1=%COUNT1%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
ping %C2% -n 1 -w 1000
SET /A COUNT2=%COUNT2%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
choice /c q /n /t 5 /d q
ping %C3% -n 1 -w 1000
SET /A COUNT3=%COUNT3%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
choice /c q /n /t 5 /d q
ping %C4% -n 1 -w 1000
SET /A COUNT4=%COUNT4%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
choice /c q /n /t 5 /d q
ping %C5% -n 1 -w 1000
SET /A COUNT5=%COUNT5%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
choice /c q /n /t 5 /d q
ping %C6% -n 1 -w 1000
SET /A COUNT6=%COUNT6%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
choice /c q /n /t 5 /d q
ping %C7% -n 1 -w 1000
SET /A COUNT=%COUNT7%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
ping %C1% -n 1 -w 1000
SET /A OVERALLCOUNT=%OVERALLCOUNT%+1
if not errorlevel 1 (GOTO START)
SET /A FAILEDPINGS=%FAILEDPINGS%+1
ECHO Internet connection down, Restarting cellular adaptor...
SET /A REBOOTCOUNT=%REBOOTCOUNT%+1
SET OVERALLCOUNT=0
SET FAILEDPINGS=0
START C:\netReset.bat
choice /c q /n /t 120 /d q
GOTO START
C:\netReset.bat
@ECHO OFF
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq openvpn-gui.exe"') DO IF %%x == openvpn-gui.exe TASKKILL /F /IM openvpn-gui.exe
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq openvpn.exe"') DO IF %%x == openvpn.exe TASKKILL /F /IM openvpn.exe
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq openvpnserv.exe"') DO IF %%x == openvpnserv.exe TASKKILL /F /IM openvpnserv.exe
choice /c q /n /t 1 /d q
powershell -Command "Restart-NetAdapter -Name "Cellular""
ECHO Restarting VPN Service...
START c:\Progra~1\OpenVPN\bin\openvpn-gui.exe --connect JaredKaragen.ovpn
ECHO VPN Service Started.
EXIT
To create these files, open a command prompt window with admin rights, go to the root of "C:\" , and type "notepad netWatch.bat". When notepad loads it will tell you that the file is not found and ask if you want to create it.... this is how. Be sure you do not save it as a text file.
To run netWatch.bat, and netReset.bat, you need admin privileges.
You must create a .lnk to a random file; and point that new .lnk at the batch file "netWatch.bat", and in "Advanced options" check the box to have it "Run as Administrator". There is no way to run this powershell command without admin priv.
Use this new .lnk to run netWatch.bat
I had several crazy issues I can not explain, which required me to run the batch in a very strange way (one batch triggering another) because when it would reach the end of the loop (after using powershell), powershell didn't seem to ever close cleanly and it would leave me back at a prompt; instead of looping to the start of the code. Thus the reason it looks like that. All good, it works still.
To configure this for your adaptor, and visit the "Network: Change Adaptor Settings" window that lists the active and inactive network adaptors. Give it a custom name now or use the current one, just know it's exact name.
Mine in the batch is "Cellular".
Sometimes it's "Ethernet 2", "Wireless" etc....
if you don't use openVPN... I suggest commenting out those lines via adding "REM " in front of those lines in netReset.bat or removing them. I can help you if necessary.
You can see how the primary batch pings multiple different locations, and if there's a valid response along the way, it starts over and waits to check again.
You can use your own choices for IP addresses/domain names.
All in all, this should be a pretty clean template for making a network adaptor reset tool. It is sooooooo nice that my machine automatically fixes itself now when I am not home. It has worked and done its job several times already... I think times need to be lengthened... but there's some very strange behavior when my network adaptor needs reset. sometimes one miner stays online; but I can't visit any webpages on it or use the internet on any other machine.... very strange stuff; or no ping response yet it can still query DNS for the IP to ping....(and all DNS caching is removed on my entire network chain so its definitely not cached). Its been a pain; but doesn't happen often.... usually...