如题所云,就是个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%
netsh interface ip set wins name=%name%
) else (
echo #经检测%name%的DHCP已经启用,现将设置为静态的DHCP,请稍候。。。。。
echo #设静态IP:%addr%,子网掩码:%mask%
netsh interface ip set address name=%name%
echo #设默认网关:%gateway%
netsh interface ip set address name=%name%
echo #设{sx}DNS:%dns1%
netsh interface ip set dns name=%name%
echo #设备用DNS:%dns2%
netsh interface ip add dns name=%name%
netsh interface ip set wins name=%name%
)
echo #
echo #显示%name%配置结果
netsh interface ip show config %name%
@pause