I use dynamic IP at home, in the company to use fixed IP, so often need to switch back and forth IP settings, very troublesome! Today is unbearable, I put together a script to ease the trouble of switching IP back and forth! I'm afraid I have forgotten.
[Plain]
@echo off
REM//Set Variable
Set name= "Local Area Connection"
REM//The following property values can be changed as needed
Set addr=172.16.18.184
Set mask=255.255.255.0
Set gateway=172.16.18.254
Set dns1=172.16.17.1
Set dns2=8.8.8.8
REM//The above properties are IP address, subnet mask, gateway, preferred DNS, alternate DNS
Echo currently available actions are:
Echo 1 is set to static IP
Echo 2 is set to dynamic IP
Echo 3 exits
echo Please select rear carriage return:
set/p operate=
If%operate%==1 Goto 1
If%operate%==2 Goto 2
If%operate%==3 Goto 3
: 1
echo is setting static IP, please wait ...
REM//Can be changed according to your needs
echo IP address =%addr%
echo mask =%mask%
echo Gateway =%gateway%
netsh interface ipv4 set address name=%name% source=static addr=%addr% mask=%mask% gateway=%gateway% gwmetric=0 >nul
echo Preferred DNS =%dns1%
netsh interface ipv4 set DNS name=%name% source=static addr=%dns1% register=primary >nul
echo Alternate DNS =%dns2%
netsh interface ipv4 add DNS name=%name% addr=%dns2% index=2 >nul
echo static IP is set!
Pause
Goto 3
: 2
Echo is setting up dynamic IP, please wait ...
ECHO is automatically getting IP addresses from DHCP ...
netsh interface ip set address "Local Area Connection" DHCP
ECHO is automatically getting DNS addresses from DHCP ...
netsh interface ip set DNS "Local Area Connection" DHCP
echo Dynamic IP has been set!
Pause
Goto 3
: 3
Exit