Edit hosts file with a batch file

So in contrast to my hosts editor app, below is the contents of a batch file to select from a list of IPs. I was using this before creating the hosts manager tool. Every once in awhile I still use this but only when I am on a system that barks at starting apps from a thumbdrive. Don’t forget to right-click and Run as…. Admin.


@echo off
TITLE Modifying your HOSTS file
COLOR F0
ECHO.
:LOOP
SET Choice=
ECHO a = server1
ECHO b = server3
ECHO c = server4
ECHO d = stage
ECHO e = devserver
SET /P Choice="Which server would you like to point your HOSTS file to? Enter a number or enter R to reset. (0,1,2,3,5,7,a,b,c,d,e,R)"
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%

ECHO.
IF /I '%Choice%'=='0' GOTO 0
IF /I '%Choice%'=='1' GOTO 1
IF /I '%Choice%'=='2' GOTO 2
IF /I '%Choice%'=='3' GOTO 3
IF /I '%Choice%'=='5' GOTO 5
IF /I '%Choice%'=='7' GOTO 7
IF /I '%Choice%'=='a' GOTO 8
IF /I '%Choice%'=='b' GOTO 9
IF /I '%Choice%'=='c' GOTO 10
IF /I '%Choice%'=='d' GOTO 11
IF /I '%Choice%'=='e' GOTO 12
IF /I '%Choice%'=='R' GOTO RESET
ECHO.
GOTO Loop

:RESET
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO #Empty hosts file>>%hosts%
GOTO END

:0
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 serv.domain.com http://www.domain.com domain.com secure.domain.com>>%hosts%
ECHO Finished
GOTO END

:1
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 serv.domain.com http://www.domain.com domain.com secure.domain.com>>%hosts%
ECHO Finished
GOTO END

:2
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 serv.domain.com http://www.domain.com domain.com secure.domain.com>>%hosts%
ECHO Finished
GOTO END

:3
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 serv.domain.com http://www.domain.com domain.com secure.domain.com>>%hosts%
ECHO Finished
GOTO END

:5
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 serv.domain.com http://www.domain.com domain.com secure.domain.com>>%hosts%
ECHO 222.222.22.22 dbcluster3>>%hosts%
ECHO Finished
GOTO END

:7
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 serv.domain.com http://www.domain.com domain.com secure.domain.com>>%hosts%
ECHO Finished
GOTO END

:8
REM server1.domain.com
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 domain.com http://www.domain.com>>%hosts%
ECHO Finished
GOTO END

:9
REM server3.domain.com
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 domain.com http://www.domain.com>>%hosts%
ECHO Finished
GOTO END

:10
REM sever4.domain.com
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 domain.com http://www.domain.com>>%hosts%
ECHO Finished
GOTO END

:11
REM stage.domain.com
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 domain.com http://www.domain.com>>%hosts%
ECHO Finished
GOTO END

:12
REM devserver.domain.com
set hosts=%windir%\system32\drivers\etc\hosts
If exist %hosts% (
del /q %hosts%)
ECHO Carrying out requested modifications to your HOSTS file
ECHO 111.111.11.11 domain.com http://www.domain.com devserver.domain.com>>%hosts%
ECHO Finished
GOTO END
:END
ECHO.
EXIT


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s