I have a local server on my Windows XP Virtual Box.
Every time my main network changes like from wifi to cable or I move to a different network the IP of my Win XP box changes.
I want to run a batch file to map the new IP to some common name in my hosts file
C:\WINDOWS\system32\drivers\etc\hosts
for example if I have now:
10.97.100.74 www.myAppServer.com
and if the ip changes to 192.168.11.9
,
I want to search for the string myAppServer
in the hosts file and replace the whole line with
192.168.11.9 www.myAppServer.com
I was able to get the current IP using:
for /f "skip=1 delims={}, " %%A in ('wmic nicconfig get ipaddress') do for /f "tokens=1" %%B in ("%%~A") do set "IP=%%~B"
set IP=%IP%
but how do I find that line and replace it?
I found this on DOS Tips
BatchSubstitute - parses a File line by line and replaces a substring