Configure IP Address Using Batch File
It’s easy to change an IP address on your computer using Control Panel, but did you know you can also do it from the Command Prompt?
Changing your IP address with the Control Panel interface isn’t difficult, but it does require clicking through a number of different windows and dialog boxes. If you’re a fan of the Command Prompt, though, you can get it done more quickly using the netsh command, which is just one of the great network utilities built into Windows.
Netsh is a command-line scripting utility that allows you to display or modify the network configuration of a computer that is currently running. Netsh commands can be run by typing commands at the netsh prompt and they can be used in batch files or scripts.
Here’s an example of how you can create a batch file that changes the IP address of the local computer. Whenever you want to change IP settings, all you have to do is execute the batch file.
Copy the code mentioned with blue color in the Notepad and save it with the .bat extension.
Changing your IP address with the Control Panel interface isn’t difficult, but it does require clicking through a number of different windows and dialog boxes. If you’re a fan of the Command Prompt, though, you can get it done more quickly using the netsh command, which is just one of the great network utilities built into Windows.
Netsh is a command-line scripting utility that allows you to display or modify the network configuration of a computer that is currently running. Netsh commands can be run by typing commands at the netsh prompt and they can be used in batch files or scripts.
Here’s an example of how you can create a batch file that changes the IP address of the local computer. Whenever you want to change IP settings, all you have to do is execute the batch file.
Copy the code mentioned with blue color in the Notepad and save it with the .bat extension.
@echo off
echo [A] Set Default IP and DNS
echo [B] Set IP And DNS
echo
=========================================================
:choice
echo Choose: A or B
SET /P C=
if [%C%]==[A] goto A
if [%C%]==[B] goto B
goto choice
:A
@echo off
echo
=========================================================
echo "Enter Connection Name:"
set /p Connection_Name=
echo =========================================================
netsh interface ip set
address %Connection_Name% source=dhcp
netsh interface ip set dns
%Connection_Name% source=dhcp
netsh interface ip set wins
%Connection_Name% source=dhcp
netsh interface ip show config
%Connection_Name%
pause
goto end
:B
@echo off
echo "Please enter Static IP
Address Information"
echo "Enter Connecction Name:"
set /p Connection_Name=
echo
=========================================================
echo "Static IP Address:"
set /p IP_Address=
echo
=========================================================
echo "Static IP Subnet Mask:"
set /p Sub_Mask=
echo
=========================================================
echo "Static IP Default
Gateway:"
set /p Default_Gateway=
echo
=========================================================
echo "Preferred DNS Server:"
set /p Preferred_DNS_Server=
echo
=========================================================
echo "Alternate DNS Server:"
set /p Alternate_DNS_Server=
echo
=========================================================
echo "Setting Static IP
Information. Please wait ....."
netsh interface ip set
address %Connection_Name% static %IP_Address%
%Sub_Mask% %Default_Gateway%
netsh interface ip add dns
%Connection_Name%
%Preferred_DNS_Server%
netsh interface ip add dns
%Connection_Name%
%Alternate_DNS_Server%
netsh interface ip show config
%Connection_Name%
pause
goto end
:end
Now, whenever you want to change IP
settings, all you have to do is run the batch file by right-clicking on the
.bat file and choose “Run as administrator“.
To change the IP address to “obtain an IP
address automatically” or to remove the IP Address, select A option after run batch
file.
To set the IP address, select B option
after run batch file. Before you set your IP address and related information,
you’ll need to enter the full name of the network for the interface you want to
change. To find this, use this command: netsh interface ipv4 show config
With the interface name in hand, you’re
ready to change the IP Address, subnet mask, gateway, and DNS settings.
--------------------------------------------------------------------------------------------------------------------------------------
Demo Video:
Helpful
ReplyDelete