This script will get the ip address to set the /etc/hosts file in Windows. I use this script in conjunction with the VPN software I use to log
into a client’s network. Once on their network, I rest my /etc/hosts file to that my system recognizes the IP address for testing purposes.
THE NSLOOKUP GETS THE SVN SERVER IP ADDRESS
THE ROUTE PRINT GETS THE VPN IP ADDRESS
@echo off
setlocal enabledelayedexpansion
set ip=
set ip2=
for /F "tokens=* skip=2" %%H in ('nslookup connection.scrapping.cc 2^>NUL') do (
set line=%%H
if "!line:~0,8!"=="Address:" set ip=!line:~10!
if "!line:~0,10!"=="Addresses:" set ip=!line:~12!
)
for /F "tokens=* skip=20" %%H in ('route print 2^>NUL') do (
set line=%%H
if "!line:~0,16!"=="Default Gateway:" set ip2=!line:~20!
)
echo 127.0.0.1 localhost > C:\WINDOWS\system32\drivers\etc\hosts
echo !ip! svnserver >> C:\WINDOWS\system32\drivers\etc\hosts
echo !ip2! www.mytestdomain.com >> C:\WINDOWS\system32\drivers\etc\hosts