Welcome Guest Search | Active Topics | Members | Log In | Register

Changing Windows IP Configuration With a Batch File Options · View
pixelninja
Posted: Monday, August 22, 2005 12:03:52 PM

Rank: Administration
Groups: Administration

Joined: 7/24/2005
Posts: 14
Location: Richardson, TX
You may download the complete source for this example here.

As a working college student, I have a consistant problem having to change my network settings. For instance, I like to download files at home, so I need certain ports open on my wireless router. This dictates that I have to use a static IP address in order to not be re-mapping ports all the time.

At school, the university requires that I use a dynamic IP address, or I cannot even connect to the network.

At work, I need to use a certain DNS server, but have a dynamic IP address. Go figure.

This means that I am constantly changing my IP configuration, and that I have three different sets of information to remember. The solution... a batch file that handles the whole shebang. This has only been tested on WinXP, by the way.


In order to have three sets of settings, I just created four files. One .bat and three .txt files so that I can just add settings for each location in the .txt files.


The ConfigIP.bat file looks like this.

Code:
@echo off
title Eric Burcham's IP Configuration Batch File - 2005
setlocal
set OK=N



:again
    set /p choice=Please enter 1[Home], 2[School] or END ??
    if /i [%choice%]==[END] endlocal&goto end
    if [%choice%]==[] goto again
    if [%choice%]==[1] goto 1
    if [%choice%]==[2] goto 2
    set /p xxx=wrong entry, press any key to exit. 
    endlocal
    goto end



:1
    echo NIC setting for Home being configured.....
    @netsh exec home.txt
    set /p see=IP changed successfully to Home Settings [9]see new setting [Enter]exit...
    if [%see%]==[9] goto show
    echo Ending IP Configuration
    goto end



:2
    echo NIC setting for School being configured.....
    @netsh exec school.txt
    set /p see=IP changed successfully to School Settings [9]see new setting [Enter]exit...
    if [%see%]==[9] goto show
    echo Ending IP Configuration
    goto end



:show
@netsh int ip show config



:end
@echo on
cls


This files presents the user with a selection; 1 or 2. Based on which selection they make, the IP settings are loaded from the following files.

home.txt
Code:
# ----------------------------------
# Interface IP Configuration         
# ----------------------------------
pushd interface ip


# Interface IP Configuration for "Wireless Network Connection"
set address name="Wireless Network Connection" source=static addr=192.168.2.50 mask=255.255.255.0
set address name="Wireless Network Connection" gateway=192.168.2.1 gwmetric=0
set dns name="Wireless Network Connection" source=static addr=192.168.2.1 register=primary


popd
# End of interface IP configuration



school.txt
Code:
# ----------------------------------
# Interface IP Configuration         
# ----------------------------------
pushd interface ip


# Interface IP Configuration for "Wireless Network Connection"
set address name="Wireless Network Connection" source=dhcp
set dns name="Wireless Network Connection" source=dhcp register=primary
set wins name="Wireless Network Connection" source=dhcp


popd
# End of interface IP configuration




You can simply add a new .txt file for each set of settings you need, and a section in the .bat file to load them. Voila! 2 second IP configuration.

You may download the complete source for this example here.




If I have seen further than others, it is by standing upon the shoulders of giants.
~Sir Isaac Newton


If I have not seen as far as others, it is because giants were standing on my shoulders.
~Hal Abelson
Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum Rss Feed : RSS

Powered by Yet Another Forum.net version 1.0.0 RC2 - 6/13/2005
Copyright © 2003-2005 Yet Another Forum.net. All rights reserved.
This page was generated in 0.470 seconds.

orum runat="server"/>