Windows 7 How to quickly switch IP script

  
I use dynamic IP at home, use fixed IP in the company, so I often need to switch IP settings back and forth, very troublesome! Today I can't bear it, I have compiled a script to ease the trouble of switching IP back and forth! I am afraid to forget, I will make a record!
[plain]
@echo off
rem //Set the variable
set NAME="Local connection"
rem //The following attribute values ​​can be Change 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 attributes are IP address, subnet mask, gateway, preferred DNS, alternate DNS
echo currently available:
echo 1 set to static IP
echo 2 set to dynamic IP
echo 3 Exit
echo Please select and press Enter:
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 change according to your needs
echo IP address= %ADDR %
echo mask= %MASK%
echo gateway= %G ATEWAY%
netsh interface ipv4 set address name=%NAME% source=static addr=%ADDR% mask=%MASK% gateway=%GATEWAY% gwmetric=0 >nul
echo Preferred DNS = %DNS1%< Br>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 dynamic IP, please wait …
Echo is getting IP address automatically from DHCP …
netsh interface ip set address "local connection" dhcp
echo is automatically obtaining DNS address from DHCP…
netsh interface ip set dns "local connection " dhcp
echo Dynamic IP is set!
pause
goto 3
:3
exit

Copyright © Windows knowledge All Rights Reserved