- @echo off
-
- ipconfig>ipc.txt
-
- netsh interface ip show address>gwc.txt
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
-
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
-
- for /f "delims=: tokens=2" %%a in ('find "IPv4 地址" ipc.txt') do set IP=%%a
-
- for /f "delims=: tokens=2" %%b in ('find "子网掩码" ipc.txt') do set mask=%%b
-
- for /f "delims=: tokens=2" %%i in ('find "默认网关" gwc.txt') do set gw=%%i
-
- netsh interface ip set address "%NetConnectionID%" static %IP% %mask% %gw% 0
-
- netsh interface ip set dns name="%NetConnectionID%" source=static addr=10.46.20.96
-
- netsh interface ip add dns name="%NetConnectionID%" addr=10.46.20.97 index=2
-
- netsh interface set interface "%NetConnectionID%" disabled
- netsh interface set interface "%NetConnectionID%" enable
-
- del ipc.txt
-
- del gwc.txt
复制代码
|