I have several routers on my network, each with their own IPv4 address and I'm trying to save that address for a batchfile to use when returning to one network from another.
for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i "Default Gateway"') do (set DG=%%i)
works well when there is only an IPv4 address, but when there's an IPv6 address as well, which is listed first in the ipconfig/all output, I haven't been able to get the address from that 2nd line where the IPv4 address is even when setting the tokens value to 7.
For reference, the line from ipconfig /all shows as~:
`Default Gateway . . . . . . . . . : fe80::2ac6:8eff:fe72:xxx%xx
10.0.0.1`
It's that second line content (the IPv4 address only) that I'm trying to save to a variable (%DG%). Any suggestions on coding without going into powershell (though if that's a quick and easy way I will resort to that?
I've also tried using only no entry for delim, e.g. for /f "delims=" %%i and also using 'for /f "delims=[ALT+255]" %%i' as the delimiter (where I key in ALT+255 vs typing in [ALT+255]) to try to use a newline for a delimiter with no luck either. No variations on tokens (from not used, to blank, to 1 through 7, and *) don't do it. I've tried several routines to set LF and CR to use in the delims along with tabs and spaces.
I have no trouble getting the first line but even getting ANYTHING on the second line eludes me.
Maybe there's another way to get the Router's IP Address. I have been using for /f "tokens=3" %%i in ('netsh wlan show interface ^| findstr /i "SSID"') do (set assid=%%i) & goto NEXT to get the SSID of the router's network, but maybe there's a command to get the IPv4 address?