Monthly Archives: February 2019

Finding the first (default) IPv4 gateway in a Windows batch script

I recently had to whip out my Windows batch scripting skills to grab the default gateway for a routing script. Here’s what I ended up with: route print | findstr /R /C:”^[ ][ ]*[ ]” | for /f “tokens=3” %%i in (‘more’) do (echo %%i & exit) >gw.tmpset /P gw=<gw.tmpdel gw.tmpecho “%gw%” This does, unfortunately, […]