IP 设置 DHCP Static WLAN 以太网
局域网下常常会有改ip的需求,为了方便,写了一个方便设定WIFI,以太网动态IP,静态IP的脚本,记录一下。
PS:
-
编码格式需要改为 ANSI;
- 网关、DNS服务器都要根据自己所需更改;
- 需要注意适配器名称是否与你电脑上一样,不一样也需要更改。
脚本如下,小白,写得不好勿喷。
@echo off
:Back
echo 请选择修改的适配器:
set /p input=WIFI :W 以太网:Y
if "%input%"=="W" goto W
if "%input%"=="w" goto W
if "%input%"=="Y" goto Y
if "%input%"=="y" goto Y
pause
exit
:W
echo now setting WIFI,please choose DHCP or Static,if choose error,input B go back
set /p inputWIFI=DHCP :D Static:S Back:B
if "%inputWIFI%"=="D" goto Wifi_Dhcp
if "%inputWIFI%"=="S" goto Wifi_Static
if "%inputWIFI%"=="B" goto Back
if "%inputWIFI%"=="d" goto Wifi_Dhcp
if "%inputWIFI%"=="s" goto Wifi_Static
if "%inputWIFI%"=="b" goto Back
pause
exit
:Y
echo now setting 以太网,choose DHCP or Static,if choose error,input B go back
set /p inputEt=DHCP :D Static:S Back:B
if "%inputEt%"=="D" goto Et_Dhcp
if "%inputEt%"=="S" goto Et_Static
if "%inputEt%"=="B" goto Back
if "%inputEt%"=="d" goto Et_Dhcp
if "%inputEt%"=="s" goto Et_Static
if "%inputEt%"=="b" goto Back
pause
exit
:Wifi_Dhcp
echo Wifi_Dhcp start----------------------------setting
set AddressName=WLAN
netsh interface ip set address name=%AddressName% source=dhcp
netsh interface ip set dns name=%AddressName% source=dhcp
rem netsh interface ip delete dns "WLAN" all
ipconfig /flushdns
netsh interface ipv4 show ipaddress interface=%AddressName%
echo Wifi_Dhcp setting----------------------------done
set /p flag=exit: e continue setting:c
if "%flag%"=="e" goto exit
if "%flag%"=="c" goto Back
if "%flag%"=="E" goto exit
if "%flag%"=="C" goto Back
pause
:Et_Dhcp
echo Et_Dhcp start----------------------------setting
set AddressName=以太网
netsh interface ip set address name=%AddressName% source=dhcp
netsh interface ip set dns name=%AddressName% source=dhcp
rem netsh interface ip delete dns "以太网" all
ipconfig /flushdns
netsh interface ipv4 show ipaddress interface=%AddressName%
echo Et_Dhcp setting----------------------------done
set /p flag=exit: e continue setting:c
if "%flag%"=="e" goto exit
if "%flag%"=="c" goto Back
if "%flag%"=="E" goto exit
if "%flag%"=="C" goto Back
pause
:Wifi_Static
echo Wifi_Static start----------------------------setting
set /p input=输入想要设置的IP:
set AddressName=WLAN
netsh interface ip set address name=%AddressName% source=static addr=%input% mask=255.255.252.0 gateway=192.168.6.1
rem netsh interface ip delete dns "WLAN" all
netsh interface ip set dns name=%AddressName% source=static addr=192.168.6.2 register=PRIMARY validate=no
netsh interface ip add dns name=%AddressName% addr=114.114.114.114 index=2 validate=no
ipconfig /flushdns
netsh interface ipv4 show ipaddress interface=%AddressName%
echo Wifi_Dhcp setting----------------------------done
set /p flag=exit: e continue setting:c
if "%flag%"=="e" goto exit
if "%flag%"=="c" goto Back
if "%flag%"=="E" goto exit
if "%flag%"=="C" goto Back
pause
:Et_Static
echo Et_Static start----------------------------setting
set /p input=输入想要设置的IP:
set AddressName=以太网
netsh interface ip set address name=%AddressName% source=static addr=%input% mask=255.255.252.0 gateway=192.168.6.1
rem netsh interface ip delete dns "以太网" all
netsh interface ip set dns name=%AddressName% source=static addr=192.168.6.2 register=PRIMARY validate=no
netsh interface ip add dns name=%AddressName% addr=114.114.114.114 index=2 validate=no
ipconfig /flushdns
netsh interface ipv4 show ipaddress interface=%AddressName%
echo Et_Static setting----------------------------done
set /p flag=exit: e continue setting:c
if "%flag%"=="e" goto exit
if "%flag%"=="c" goto Back
if "%flag%"=="E" goto exit
if "%flag%"=="C" goto Back
pause
:exit
exit