I am writing a batch file to extract the Default Gateway so that I can ping any and all, and pipe the results to a text file.
I use Route Print to get the default gateway detail and pipe it thru Findstr.
It works fine when there is only one default gateway, however some have a VPN adapter as well as the Ethernet adapter.
Route print returns data, in particular the data shown below
IPv4 Route Table
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 18.104.22.168 22.214.171.124 18000
0.0.0.0 0.0.0.0 192.168.0.200 192.168.0.12 10
126.96.36.199 255.0.0.0 On-link 188.8.131.52 9256
When I use the code below (kindly used from http://www.petri.co.il/forums/showthread.php?t=47121
) I can get the 1st Def GW (184.108.40.206) in the list, but cant crack extracting the second (192.168.0.200)
@For /f "tokens=3" %%* in (
'route.exe print ^|findstr "\<0.0.0.0\>"'
) Do @Set "DefaultGateway=%%*"
H E L P