如何用批处理桥接两个网卡
@echo off
wmic exit || exit /b 1
for /f "delims=" %%a in ('
wmic nic where "NetConnectionID > ''" get NetConnectionID^,PNPDeviceID /value
') do for /f "delims=" %%i in ("%%a") do (
rem 这里多加了一个for是为了过滤wmic输出中的多余回车符
set "%%i"
set "#=%%i"
setlocal enableDelayedExpansion
if /i "!#:~,11!" == "PNPDeviceID" (
if "!PNPDeviceID:DEV_4727=!" neq "!PNPDeviceID!" (
echo 第一个网卡: "!NetConnectionID!"
echo netsh int ip set addr "!NetConnectionID!" static 192.168.1.X 255.255.255.0
) else if /i "!PNPDeviceID:~,3!" == "PCI" (
echo 第二个网卡: "!NetConnectionID!"
echo netsh int ip set addr "!NetConnectionID!" static 172.23.1.X 255.255.0.0
)
)
endlocal
)
pause