Monday, August 31, 2009

Batch files for changing IP Address and Domains

The following post provide information about how to create batch files for changing IP Addresses and Domains easily. Just copy the contents marked between ****** into a text file and give the file extension as .bat


CHANGING IP ADDRESS

We use the netsh command to change the IP address. The following batch files help in changing the IP Address from dynamic to static and vice versa:

Provide Static IP
********************************************************************************
@ECHO OFF

set varip=192.68.10.12
set varsm=255.255.255.248
set vargw=68.23.41.1
set vardns1=68.23.41.1
set vardns2=68.23.41.2

REM ***** You don’t need to change anything below this line! ******

ECHO Setting IP Address and Subnet Mask
netsh int ip set address name = "Local Area Connection" source = static addr = %varip% mask = %varsm%

ECHO Setting Gateway
netsh int ip set address name = "Local Area Connection" gateway = %vargw% gwmetric = 1

ECHO Setting Primary DNS
netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1%

ECHO Setting Secondary DNS
netsh int ip add dns name = "Local Area Connection" addr = %vardns2%

ECHO Here are the new settings for %computername%:
netsh int ip show config

pause
********************************************************************************

Remove Static IP and change to Dynamic
********************************************************************************
@ECHO OFF

ECHO Setting IP Address and Subnet Mask to Dynamic
netsh int ip set address name = "Local Area Connection" source=dhcp
ECHO Setting DNS Server Address to Dynamic
netsh int ip set dns name = "Local Area Connection" source = dhcp

ECHO Renewing IP Address
ipconfig /renew

pause
********************************************************************************

CHANING DOMAINS

To change the domain, we need to use the netdom.exe, which will get installed along with the Windows XP Support Tools.

To Join to a Domain
********************************************************************************
netdom join %computername% /d:domainName /ud:userName /pd:password /reboot:XX in seconds after which computer reboots
********************************************************************************

To Remove from Domain
********************************************************************************
netdom remove %computername% /d:domainName /ud:userName /pd:password /reboot:XX
********************************************************************************


Installing Netdom.exe

Installation File Name: WindowsXP-KB838079-SupportTools-ENU
Download Location: Download
Command Information: See Here

After installation of the support tools, the netdom.exe will be available in C:\Program Files\Support Tools. Copy this file into the location where you will be running the batch file.

No comments: