感谢深蓝软件群友 G K 为大家分享。
实现的功能为:
批处理为:
@echo off
for /f "delims=" %%a in ('wmic NIC where "NetEnabled='TRUE'" get MACAddress^,NetConnectionID /value^|find "="') do set %%a
for /f "delims=" %%a in ('wmic NICCONFIG where "MACAddress='%MACAddress%'" get IPAddress /value^|find "="') do set %%a
for /f "delims={," %%a in ("%IPAddress%") do set ip=%%~a
for /f "tokens=1-4 delims=." %%a in ("%ip%") do set last=%%d
echo;%ip%
echo;%last%
echo;%NetConnectionID%
netsh interface ipv4 set address name="本地连接" addr=192.168.1.%last% mask=255.255.255.0 gwmetric=30
netsh interface ipv4 add address name="本地连接" addr=192.168.2.%last% mask=255.255.255.0 gateway=192.168.2.1 gwmetric=1
exit