Finding default gateway in an openvpn environment in windows

Posted on


I need to find the default gateway in a openvpn scenario where the route output looks like that:

IPv4 Route Table
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric

So I googled around a bit and a found this script here:

@For /f "tokens=3" %%* in (
   'route.exe print ^|findstr "<>"'
   ) Do @Set "DefaultGateway=%%*"

echo %DefaultGateway%

This works, but matches both lines in the route output.

But I need to find this line:     10

So I tried to modify the findstr parameter like this:

findstr "<>.<>"

in the expectation that ‘.’ will match for the tab between the columns.
But it doesn’t. It will still set DefaultGateway to

I couldn’t find a clue in MS documentation either.
Maybe someone knows the right expression?
Thanks a lot.


Try this:

For /f "tokens=3" %%* in (
   'route print ^|findstr "<*>"'
   ) Do @Set "DefaultGateway=%%*"

echo %DefaultGateway%

And you can check findstr /? for more informations.

Leave a Reply

Your email address will not be published. Required fields are marked *