Saturday, 30 June 2012

Change Ip address with batch file

My boss having Laptop & he having different IP address at office & 

home, & every day when he comes to office he need to change his 

laptop IP adress everyday. So i written a batch script to change IP 

address with single click, & i know this problem is with many people 

so i am sharing this batch script with you...

OK let's starting creating batch file

Copy the code below :


@echo off 
echo Choose: 
echo [A] Set Static IP.  
echo [B] Set Obtain adress automatically.
echo. 
:choice 
SET /P C=[A,B]? 
for %%? in (A) do if /I "%C%"=="%%?" goto A 
for %%? in (B) do if /I "%C%"=="%%?" goto B 
goto choice 

:A 
echo "Setting Static Ip" 
netsh interface ip set address "Local Area Connection" static 172.16.0.6 255.255.0.0 %D_Gate% 172.16.0.100
netsh int ip set dns "Local Area Connection" static 123.123.123.123
netsh int ip add dns "Local Area Connection" 124.124.124.124 
netsh int ip show config 
pause 
goto end

:B 
@ECHO OFF 
ECHO Resetting IP Address and Subnet Mask For DHCP 
netsh int ip set address name = "Local Area Connection" source = dhcp
netsh int ip set dns name = "Local Area Connection" source = dhcp
ipconfig /renew

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

pause 
goto end 
:end
echo Visit Askmetricks.blogspot.com
pause


Now paste the code into Notepad & save it as IP changer.bat

Very Important instruction :-

in this batch script i had defined my ip address ,DNS ,Default 

gateway & Subnet mask.

but you need to replace as per your network settings....

What to change ?

172.16.0.6   is my IP address

255.255.0.0  is my Subnet mask

172.16.0.100  is my Default gateway

123.123.123.123 is my Primary DNS

124.124.124.124  is my Secondary DNS

Replace all above addresses with your network addresses & save the 

file

That's it...

Work Smarter...



2 comments :

  1. mast re.....keep giving such tips....!!!good to learn from you...

    ReplyDelete