 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
|