I want to run "ipconfig", and put the gateway IP address into a variable. I found this solution on another forum:
Code: Select all
set "ip="
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "Default"') do if not defined ip set ip=%%b
http://stackoverflow.com/questions/2236 ... batch-file
It works perfectly for me, but I simply don't understand it! Can anyone explain it to me (very slowly)?
Ideally, I want the script to work on any version of Windows (and in any region). Will this line of code work on any version of Windows (or at least XP onwards)? And, am I right in thinking that searching for the text "Default" would only work if the language was set to English? If so, are there any other ways to get the gateway IP? Ooh -- and will this work if the gateway uses IPv6 instead of IPv4?
Sorry -- so many questions! Any little tips or hints would be greatly appreciated!
EDIT: I just found this link, which goes a long way to explain what's happening. I'm going to need to re-read it a dozen times to wrap my head round it, I think!
https://blogs.msdn.microsoft.com/oldnew ... 00/?p=7003