I know it is possible to direct output of a command to a text file, then set specific variable information out of this..
I need a batch file that will do an "nslookup www.test.com
> lookup.txt" then get the IP of the domain and set is as a variable.
I found an example online to get the gateway IP and set the IP as a variable:
echo > "%userprofile%\gate.txt"
ipconfig | find /i "gate" > "%userprofile%\gate.txt"
For /F "Tokens=2* Delims=: usebackq" %%i In ("%userprofile%\gate.txt")
Do Set gate=%%i
del /f /q "%userprofile%\gate.txt"
set gate=%gate: =%
for /f "Tokens=1,2,3,4 Delims=." %%i In ("%gate%") Do Set a=%%i& Set b=%%j& Set c=%%k& Set d=%%l
I want to do the same thing as the example above but get the IP of a website via NSlookup and then set the IP as a variable. I need a script to do this since the IP of this particular website uses dynamic DNS and the IP will change frequently... so I need the script to detect the new IP via the nslookup.
If there are multiple IP addresses for the website, i just need to use the first one in the list.
Can you provide an example how to do this?