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. Advertisements

  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. Advertisements

  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. Advertisements

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Replies:
    2
    Views:
    1,605
  2. spec
    Replies:
    7
    Views:
    1,825
    Peter
    Jun 5, 2006
  3. Alan Browne

    Snapshot restraint - edit, edit, edit

    Alan Browne, May 5, 2005, in forum: Digital Photography
    Replies:
    24
    Views:
    2,708
    Mr. Mark
    May 10, 2005
  4. Patrick

    Snapshot restraint - edit, edit, edit

    Patrick, May 6, 2005, in forum: Digital Photography
    Replies:
    0
    Views:
    1,615
    Patrick
    May 6, 2005
  5. ljljl

    Hosts file in Windows XP

    ljljl, Dec 17, 2005, in forum: Computer Support
    Replies:
    6
    Views:
    1,612
  6. ClueLess

    HOSTS file in XP?

    ClueLess, Sep 18, 2007, in forum: Computer Support
    Replies:
    6
    Views:
    1,291
    Tester
    Sep 20, 2007
  7. Penang

    Who is in charged of the Hosts file in XP ??

    Penang, Oct 27, 2008, in forum: Computer Support
    Replies:
    4
    Views:
    561
    Leo Kowalski
    Oct 27, 2008
  8. Penang

    Who is in charged of the Hosts file in XP ??

    Penang, Oct 27, 2008, in forum: Computer Security
    Replies:
    5
    Views:
    1,095
    Unruh
    Oct 27, 2008
Loading...