如题所云,就是个BATCH文件

内容如下

@echo off
title "简单的静态/动态DHCP转换工具"
echo.
echo #设置环境变量
set name="本地连接"
set addr=172.0.0.100
set mask=255.255.255.0
set gateway=172.0.0.1
set dns1=202.101.103.55
set dns2=218.85.157.99

echo #判断%name%是否启用DHCP
for /F " tokens=1,2,* " %%i in ('netsh interface ip show config %name% ') do if %%i==DHCP if %%j==启用 if %%k==否 (
echo #经检测%name%的DHCP已经关闭,现将启用DHCP,请稍候。。。。。
echo #%name%的接口IP配置
echo #设自动获取IP
netsh interface ip set address name=%name% source=dhcp >NUL
echo #设自动获取DNS
netsh interface ip set dns name=%name% source=dhcp register=PRIMARY >NUL
netsh interface ip set wins name=%name% source=dhcp >NUL
) else (
echo #经检测%name%的DHCP已经启用,现将设置为静态的DHCP,请稍候。。。。。
echo #设静态IP:%addr%,子网掩码:%mask%
netsh interface ip set address name=%name% source=static addr=%addr% mask=%mask% >NUL
echo #设默认网关:%gateway%
netsh interface ip set address name=%name% gateway=%gateway% gwmetric=0 >NUL
echo #设首选DNS:%dns1%
netsh interface ip set dns name=%name% source=static addr=%dns1% register=PRIMARY >NUL
echo #设备用DNS:%dns2%
netsh interface ip add dns name=%name% addr=%dns2% index=2 >NUL
netsh interface ip set wins name=%name% source=static addr=none >NUL
)
echo #
echo #显示%name%配置结果
netsh interface ip show config %name%

@pause

标签: none

添加新评论