@echo off
::用法：manualSetIp.bat 接口名称 IP 掩码 网关 DNS ；例如（manualSetIp.bat 本地连接 192.168.23.124 192.168.23.1 192.168.58.110 NULL NULL 192.168.58.111 NULL）
cacls.exe "%SystemDrive%\System Volume Information" >nul 2>nul
if %errorlevel%==0 goto Admin
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
echo Set RequestUAC = CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"
echo RequestUAC.ShellExecute "%~s0","%1 %2 %3 %4 %5 %6 %7 %8","","runas",1 >>"%temp%\getadmin.vbs"
echo WScript.Quit >>"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs" /f
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
exit

:Admin
	
set intf=%1
set pcIp=%2
set pcGw=%3
set pcDns=%4
set pcSecIp=%5
set pcSecGw=%6
set pcDns2=%7
set mask=%8
echo manualSetIp 1:%intf% 2:%pcIp% 3:%pcGw% 4:%pcDns% 5:%pcSecIp% 6:%pcSecGw% 7:%pcDns2% 8:%mask%
if %mask%==NULL (set mask=255.255.255.0)
if %pcGw%==NULL ( netsh interface ipv4 set address name="%intf%" source=static addr=%pcIp% mask=%mask% gwmetric=0 ) else ( netsh interface ipv4 set address name="%intf%" source=static addr=%pcIp% mask=%mask% gateway=%pcGw% gwmetric=0 )
if %pcDns%==NULL ( echo no dns ) else ( netsh interface ip set dns "%intf%" static %pcDns% primary )

if %pcSecIp%==NULL ( echo no sec ip ) else ( netsh interface ipv4 add address name="%intf%" addr=%pcSecIp% mask=%mask% gwmetric=0 store=active )
if %pcSecGw%==NULL ( echo no sec ip ) else ( netsh interface ip add address name="%intf%" gateway=%pcSecGw% gwmetric=0 store=active )
if %pcDns2%==NULL ( echo no sec dns ) else ( netsh interface ip add dnsservers name="%intf%" address=%pcDns2% index=2 )