Re: PSA: Simple Wi-Fi gateway killswitch that works with OpenVPN config files

Maria Sophia <[email protected]> Thu, 16 Jul 2026 19:57:24 -0400
Newsgroups alt.comp.os.windows-10,alt.comp.os.windows-11,alt.comp.microsoft.windows
Organization BWH Usenet Archive (https://usenet.blueworldhosting.com)
Message-ID <[email protected]>
Here is the old version that Zaidy helped write five years ago.
It worked fine with the dumb USB Wi-Fi dongle.
But it needed the previous enhancements to work with a Wi-Fi NIC.

  @echo off
  REM nettoggle.bat 
  REM v1p1 by Zaidy036 20210207 on alt.comp.os.windows-10
  set defgw=192.168.1.1
  set "ip="
  for /f "tokens=2,3 delims={,}" %%a in ('"WMIC NICConfig where IPEnabled="True" get DefaultIPGateway /value | find "I" "') do if not defined ip set ip=%%~a
  IF "%ip%"=="%defgw%" ( %comspec% /c %windir%\system32\route.exe delete 0.0.0.0 %defgw%) ELSE ( %comspec% /c %windir%\system32\route.exe add 0.0.0.0 mask 0.0.0.0 %defgw%)
  exit
  
  REM nettoggle.lnk
  REM  C:\Windows\System32\schtasks.exe /run /TN "task nettoggle"
  REM                                                                                                                      ~                               
  REM taskschd.msc
  REM  task nettoggle 
  REM  Run with highest privileges = checked
  REM  Action = Start a program
  REM  Program/script = %comspec%
  REM  Add arguments = /c start "" c:\pathto\nettoggle.bat
  REM 
  REM nettoggle.bat
  REM  @echo off
  REM  set defgw=192.168.1.1
  REM  set "ip="
  REM  for /f "tokens=2,3 delims={,}" %%a in ('"WMIC NICConfig where IPEnabled="True" get DefaultIPGateway /value | find "I" "') do if not defined ip set ip=%%~a
  REM  IF "%ip%"=="%defgw%" ( %comspec% /c %windir%\system32\route.exe delete 0.0.0.0 %defgw%) ELSE ( %comspec% /c %windir%\system32\route.exe add 0.0.0.0 mask 0.0.0.0 %defgw%)
  REM  exit
  REM 
  REM
  REM
  REM USE MODEL:
  REM a. Hit the taskbar shortcut (gwtoggle.lnk)
  REM b. If the network was on, it (the gateway) will be turned off.
  REM    If the network was off, it (the gateway) will be turned on.
  REM    The Windows hardware icons will show the status accordingly.
  REM c. If VPN was on, nothing will happen until the VPN drops.
  REM    If the VPN subsequently drops, the network (gateway) will be turned off.
  REM    The Windows hardware icons will show the status accordingly.
  REM 
  REM TASKBAR SHORTCUT:
  REM gwtoggle.lnk
  REM  Target = C:\Windows\System32\schtasks.exe /run /TN "task gwtoggle"
  REM 
  REM SCHEDULED TASK:                                                                                                                                                   
  REM taskschd.msc
  REM  task gwtoggle 
  REM  Run with highest privileges = checked
  REM  Action = Start a program
  REM  Program/script = %comspec%
  REM  Add arguments = /c start "anything" c:\pathto\gwtoggle.bat
  REM 
  REM BATCH SCRIPT:
  REM c:\pathto\gwtoggle.bat
  REM  @echo off
  REM  set defgw=192.168.1.1
  REM  set "ip="
  REM  for /f "tokens=2,3 delims={,}" %%a in ('"WMIC NICConfig where IPEnabled="True" get DefaultIPGateway /value | find "I" "') do if not defined ip set ip=%%~a
  REM  IF "%ip%"=="%defgw%" ( %comspec% /c %windir%\system32\route.exe delete 0.0.0.0 %defgw%) ELSE ( %comspec% /c %windir%\system32\route.exe add 0.0.0.0 mask 0.0.0.0 %defgw%)
  REM  exit
  REM 
  REM SHORTCUT ICONS:
  REM https://www.flaticon.com/free-icons/on-off
  REM https://icons8.com/icons/set/on-off
  REM https://iconarchive.com/tag/on-off
  REM 
  REM Example icon:
  REM https://cdn.icon-icons.com/icons2/1535/PNG/512/3298613-onoff-switch-switchoff-switchon_106998.png
  
  ::  end of c:\data\sys\batch\nettoggle.bat
-- 
Usenet is a wonderful place to discuss topics among thousands of experts.