script to edit hosts file in xp?

Discussion in 'Wireless Networking' started by MZ, Jan 6, 2005.

  1. MZ

    MZ Guest

    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.
     
    MZ, Jan 6, 2005
    #1
    1. Advertising

  2. MZ

    robbity Guest

    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" <> wrote in message
    news:aaudnavbMIikWkHcRVn-
    ...
    > 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.
    >
    >
     
    robbity, Jan 6, 2005
    #2
    1. Advertising

  3. MZ

    MZ Guest

    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" <> wrote in message news:...
    > 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" <> wrote in message
    > news:aaudnavbMIikWkHcRVn-
    > ...
    > > 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.
    > >
    > >

    >
    >
     
    MZ, Jan 6, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. spec
    Replies:
    7
    Views:
    1,353
    Peter
    Jun 5, 2006
  2. Alan Browne

    Snapshot restraint - edit, edit, edit

    Alan Browne, May 5, 2005, in forum: Digital Photography
    Replies:
    24
    Views:
    1,297
    Mr. Mark
    May 10, 2005
  3. Patrick

    Snapshot restraint - edit, edit, edit

    Patrick, May 6, 2005, in forum: Digital Photography
    Replies:
    0
    Views:
    666
    Patrick
    May 6, 2005
  4. Matt Silberstein

    Snapshot restraint - edit, edit, ed

    Matt Silberstein, May 6, 2005, in forum: Digital Photography
    Replies:
    0
    Views:
    550
    Matt Silberstein
    May 6, 2005
  5. Ben Rosengart

    Snapshot restraint - edit, edit, ed

    Ben Rosengart, May 6, 2005, in forum: Digital Photography
    Replies:
    0
    Views:
    379
    Ben Rosengart
    May 6, 2005
Loading...

Share This Page