/bin/log

Log my thoughts

Home About GitHub

14 May 2013
windows bat to add hosts

Point domain.com to 127.0.0.1

@echo off
set hostspath=%windir%\System32\drivers\etc\hosts
echo. >> %hostspath%
REM echo #comment>> %hostspath%
echo 127.0.0.1 www.domain.com>> %hostspath%
echo 127.0.0.1 domain.com>> %hostspath%
ipconfig /flushdns
exit

Clean up

REM This bat remove all entries of domain.com from hosts file
findstr /v domain.com^
        C:\WINDOWS\system32\drivers\etc\hosts^
        > C:\WINDOWS\system32\drivers\etc\hosts.tmp

copy C:\WINDOWS\system32\drivers\etc\hosts.tmp^
     C:\WINDOWS\system32\drivers\etc\hosts

del C:\WINDOWS\system32\drivers\etc\hosts.tmp

Some tips

REM make new line
echo.
echo:
References:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/findstr.mspx


Carpe diem,
JZR at 15:57

Home About GitHub