固定IP
@echo off
REM 声明采用UTF-8编码
chcp 65001
REM netsh interface ip show interfaces
REM ipconfig/all
set Nic=以太网
REM set /p Nic=输入网卡名称:
set Addr=192.168.1.1
set Mask=255.255.255.0
set Gway=192.168.1.0
REM set Dns1=10.15.0.1
REM set Dns2=10.100.1.2
REM set Wins1=10.15.0.1
REM set Wins2=10.100.1.2
echo ------------------------------------------------------
echo 正在进行IP设置,请稍等
echo. IP地址 = %Addr%
echo. 子网掩码 = %Mask%
echo. 默认网关 = %Gway%
netsh interface ipv4 set address name=%Nic% source=static addr=%Addr% mask=%Mask% gateway=%Gway% gwmetric=0
rem echo. 首选DNS = %Dns1%
rem netsh interface ip set dns name=%Nic% source=static addr=%Dns1% register=PRIMARY >nul
rem echo. 备用DNS = %Dns2%
rem netsh interface ip add dns name=%Nic% addr=%Dns2% index=2 >nul
rem echo. 首选WINS = %Wins1%
rem netsh interface ip set wins name=%Nic% source=static addr=%Wins1% register=PRIMARY >nul
rem echo. 备用WINS = %Wins2%
rem netsh interface ip add wins name=%Nic% addr=%Wins2% index=2 >nul
echo ------------------------------------------------------
echo IP设置完成!
pause
自动获取IP
@echo off
REM 声明采用UTF-8编码
chcp 65001
netsh interface ipv4 set address name="以太网" source=dhcp
netsh interface ipv4 set dnsservers name="以太网" source=dhcp
pause
来源:CSDN
作者:Kelvin_Ngan
链接:https://blog.csdn.net/Kelvin_Yan/article/details/103710234