@echo off title netsh-ipv4 (by huanu) :nc rem //选择网卡 echo --请根据网卡名选择网卡: echo ex 、退出(exit) echo 01 、以太网(win8win10) echo 02 、本地连接(win xpwin7) echo 03 、WLAN echo 04 、Enternet echo 05 、Local Area Connection echo. echo --请选择后回车: set /p netname= if %netname%==ex exit if %netname%==01 set NAME="以太网" if %netname%==02 set NAME="本地连接" if %netname%==03 set NAME="WLAN" if %netname%==04 set NAME="Enternet" if %netname%==05 set NAME="Local Area Connection" echo 您选择的网卡是%NAME% echo. rem //选择要设置的IP地址: :list echo ---选择要设置的IP地址: echo nc 、返回重新选择网卡(back) echo ex 、退出(exit) echo 01 、从DHCP自动获取IP地址 echo 02 、公司工位 IP:192.168.90.5 echo. echo ---请选择后回车: set /p operate= if %operate%==nc goto nc if %operate%==ex exit if %operate%==01 goto dhcp if %operate%==02 goto 02 echo. rem //设置IP地址 :dhcp echo 正在设置动态IP,请稍等... echo 正在从DHCP自动获取IP地址... netsh interface ip set address %NAME% dhcp echo 正在从DHCP自动获取DNS地址... netsh interface ip set dns %NAME% dhcp echo %NAME%地址已自动获取成功! pause & exit :02 rem //可以根据你的需要更改 set ADDR=192.168.90.5 set MASK=255.255.255.0 set GATEWAY=192.168.90.1 set DNS1=114.114.114.114 set DNS2=8.8.8.8 echo 正在设置%NAME% IP地址,请稍等... rem //设置并打印在屏幕上 echo IP地址 = %ADDR% echo 掩码 = %MASK% echo 网关 = %GATEWAY% netsh interface ipv4 set address %NAME% static %ADDR% %MASK% %GATEWAY% echo 首选DNS = %DNS1% netsh interface ipv4 set dns %NAME% static %DNS1% echo 备用DNS = %DNS2% if "%DNS2%"=="" (echo DNS2为空) else (netsh interface ipv4 add dns %NAME% %DNS2%) echo %NAME% IP已设置完成! pause & exit