script to edit hosts file in xp?

G

Guest

Guest
Archived from groups: microsoft.public.windows.networking.wireless (More info?)

Not sure if this is the best newsgroup to post this in, but here goes...

I use two IP addresses (both through wired and wireless connections) on my
laptop - one for work, one for home. Does anyone know how to write a simple
script that will detect the IP address and then choose which of two "hosts"
files to use? When at home, I want mydomain.com to be associated with
192.168.X.Y, but at work I don't want that association.

Currently, I have to go in manually each time and rename hosts to hosts.tmp
when at work, and then rename it back to hosts when I get home. I'd like
this to be done automatically.
 
G

Guest

Guest
Archived from groups: microsoft.public.windows.networking.wireless (More info?)

hi

ren c:\windows\system32\drivers\etc\hosts hosts.tmp

save the line above as a bat file, ie. Host_to_tmp.bat

ren c:\windows\system32\drivers\etc\hosts.tmp hosts

save this line as another bat file, ie Hosts_From_tmp.bat

then just run which ever you require.
I am making some assumptions like your hosts file is located in
c:\windows\system32\drivers\etc if it is not just substitute the part.

You could go much fancier and use variables to chose which way you wanted to
go etc, but I only had about 2 mins to spare.

HTH
Rob


"MZ" <zarellam@removetwcny.rr.comspam> wrote in message
news:aaudnavbMIikWkHcRVn-
vA@giganews.com...
> Not sure if this is the best newsgroup to post this in, but here goes...
>
> I use two IP addresses (both through wired and wireless connections) on my
> laptop - one for work, one for home. Does anyone know how to write a
> simple
> script that will detect the IP address and then choose which of two
> "hosts"
> files to use? When at home, I want mydomain.com to be associated with
> 192.168.X.Y, but at work I don't want that association.
>
> Currently, I have to go in manually each time and rename hosts to
> hosts.tmp
> when at work, and then rename it back to hosts when I get home. I'd like
> this to be done automatically.
>
>
 
G

Guest

Guest
Archived from groups: microsoft.public.windows.networking.wireless (More info?)

Do you know of a command which allows you to retrieve the IP address? If I
had that information in the batch file, I may be able to let it chose which
way to go automatically.

"robbity" <me@home.com> wrote in message news:41dd3219@quokka.wn.com.au...
> hi
>
> ren c:\windows\system32\drivers\etc\hosts hosts.tmp
>
> save the line above as a bat file, ie. Host_to_tmp.bat
>
> ren c:\windows\system32\drivers\etc\hosts.tmp hosts
>
> save this line as another bat file, ie Hosts_From_tmp.bat
>
> then just run which ever you require.
> I am making some assumptions like your hosts file is located in
> c:\windows\system32\drivers\etc if it is not just substitute the part.
>
> You could go much fancier and use variables to chose which way you wanted
to
> go etc, but I only had about 2 mins to spare.
>
> HTH
> Rob
>
>
> "MZ" <zarellam@removetwcny.rr.comspam> wrote in message
> news:aaudnavbMIikWkHcRVn-
> vA@giganews.com...
> > Not sure if this is the best newsgroup to post this in, but here goes...
> >
> > I use two IP addresses (both through wired and wireless connections) on
my
> > laptop - one for work, one for home. Does anyone know how to write a
> > simple
> > script that will detect the IP address and then choose which of two
> > "hosts"
> > files to use? When at home, I want mydomain.com to be associated with
> > 192.168.X.Y, but at work I don't want that association.
> >
> > Currently, I have to go in manually each time and rename hosts to
> > hosts.tmp
> > when at work, and then rename it back to hosts when I get home. I'd
like
> > this to be done automatically.
> >
> >
>
>