
@echo off
rem 添加一个额外网段的ip但不改变/保留最后一段的ip数字
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
set "NetConnectionID="
set "MACAddress="
set "IPAddress="
for /f "delims=" %%a in ('wmic nic where "NetEnabled=TRUE and PhysicalAdapter=TRUE" get NetConnectionID^,MACAddress /value^|find "="') do set %%a
if not defined NetConnectionID (echoFailed to get NetConnectionID&pause&exit)
for /f "delims=" %%a in ('wmic nicconfig where "MACAddress='%MACAddress%'" get IPAddress^,DHCPEnabled /value^|find "="') do set %%a
if not defined IPAddress (echoFailed to get IPAddress&pause&exit)
if /i "%DHCPEnabled%" equ "TRUE" (echoDHCP is Enabled&pause&exit)
set IPAddress=%IPAddress:{=}%
set IPAddress=%IPAddress:}=%
set IPAddress=%IPAddress:"=%
for /f "delims=," %%a in ("%IPAddress%") do (
set oldip=%%a
for /f "tokens=1-4 delims=." %%b in ("%%a") do (
set #1=%%b
set #2=%%c
set #3=%%d
set #4=%%e
)
)
set newip=192.168.20.%#4%
set newipsubnet=255.255.255.0
echonetconnection=%NetConnectionID%
echooldip=%oldip%
echomac=%MACAddress%
echo--------------------------
echonewip=%newip%
echonewipsubnet=%newipsubnet%
netsh interface ip add address "%NetConnectionID%" %newip% %newipsubnet%
echo%#% +%$%%$%/%@% %z%
pause
exit
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)