HOW TO SET STATIC IP AUTOMATICALLY WITH .BAT FILE

Recently i came through a situation when i had to set the static ip address to hundreds of systems installed in a premises of an organization and for that i had to go to
Network and Sharing Center -> Change Adapter setting ->Ethernet or Local Area Network ->Right Click ->Properties->IPV4

These all steps takes around 2 minutes per system, so to avoid it and make the process fast i wrote a batch script in visual basic.

Copy and paste the following code in notepad and save it as test.bat or any name but .bat extension and run it as administrator

Make sure you are running this script as Admin, Otherwise it won’t work! (right click on the script, click “Run As Administrator”)

@echo off 
echo Notice: Make sure you are running this script as Admin, Otherwise it won't work! (right click on the script, click "Run As Administrator")
goto A 

:A 
@echo off 
echo "Please enter Static IP Address Information" 
echo "Static IP Address:" 
set /p IP_Addr=

echo "Setting Static IP Information" 
netsh interface ip set address name="Local Area Connection" static 192.168.1.%IP_Addr% 255.255.255.0 192.168.1.1
netsh interface ip set address name="Ethernet" static 192.168.1.%IP_Addr% 255.255.255.0 192.168.1.1
netsh int ipv4 set dns name="Local Area Connection" static 8.8.8.8 primary validate=no
netsh int ipv4 add dns name="Local Area Connection" 8.8.4.4 index=2
netsh int ipv4 set dns name="Ethernet" static 8.8.8.8 primary validate=no
netsh int ipv4 add dns name="Ethernet" 8.8.4.4 index=2
ipconfig /flushdns
netsh int ip show config 
pause 
goto end

:end

About Eshwar Dubey

Leave a Reply

Your email address will not be published. Required fields are marked *