BAT 修改IP地址为静态或者自动获取

:: admin运行
@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )


:: 设置IP地址
set /p choice=请选择设置类型(1:WIFI静态IP / 2:WIFI自动获取IP/3:LAN静态IP / 4:LAN自动获取IP):
echo.
if "%choice%"=="1" goto ip1
if "%choice%"=="2" goto ip2
if "%choice%"=="3" goto ip3
if "%choice%"=="4" goto ip4
goto main
:ip1
echo IP自动设置开始...
echo.
echo 正在设置IP及子网掩码
cmd /c netsh interface ip set address name="WLAN" source=static addr=10.200.13.195 mask=255.255.255.0

echo gateway=192.168.0.1 gwmetric=1
echo 正在设置DNS服务器

echo cmd /c netsh interface ip add dnsservers name="WLAN" address=192.168.0.1 index=1 
echo cmd /c netsh interface ip add dnsservers name="WLAN" address=192.168.0.1 index=2
echo 设置完成
pause
exit
if errorlevel 2 goto main
if errorlevel 1 goto end
:ip2
echo IP自动设置开始....
echo.
echo 自动获取IP地址....
netsh interface ip set address name = "WLAN" source = dhcp
echo 自动获取DNS服务器....
netsh interface ip set dns name = "WLAN" source = dhcp
@rem 设置自动获取IP
echo 设置完成
pause
exit
if errorlevel 2 goto main
if errorlevel 1 goto end
:end

:ip3
echo IP自动设置开始...
echo.
echo 正在设置IP及子网掩码
cmd /c netsh interface ip set address name="以太网 2" source=static addr=10.200.13.195 mask=255.255.255.0

echo gateway=192.168.0.1 gwmetric=1
echo 正在设置DNS服务器

echo cmd /c netsh interface ip add dnsservers name="以太网 2" address=192.168.0.1 index=1 
echo cmd /c netsh interface ip add dnsservers name="以太网 2" address=192.168.0.1 index=2
echo 设置完成
pause
exit
if errorlevel 2 goto main
if errorlevel 1 goto end
:ip4
echo IP自动设置开始....
echo.
echo 自动获取IP地址....
netsh interface ip set address name = "以太网 2" source = dhcp
echo 自动获取DNS服务器....
netsh interface ip set dns name = "以太网 2" source = dhcp
@rem 设置自动获取IP
echo 设置完成
pause
exit
if errorlevel 2 goto main
if errorlevel 1 goto end
:end



评论

此博客中的热门博文

LTE: 小区RS参考信号功率与RRU发射功率的计算-[转]

LTE – 网络架构及网元实体-[转]

学习谏言