发布网友
共1个回答
热心网友
@echo off
SetLocal EnableDelayedExpansion
REM 依次检测同段IP,在线主机直接跳过,不在线的则自动设置成本机IP
for /l %%a in (2,1,254) do (
set IP=172.16.20.%%a
call :check
echo.&set /p =!IP! <nul
if defined online (echo 主机占用中,自动跳过) else (
netsh interface ip set address name="本地连接" static !IP! 255.255.255.0 172.16.20.1 1 >nul
echo 修改完成&goto :end
)
)
echo.
echo.&echo 找不到可用IP
:end
echo.&echo 按任意键退出
pause>nul
exit
:check
set online=
arp -a|find "%IP%" >nul 2>nul&&set online=1
ping -n 1 %IP% >nul 2>nul
arp -a|find "%IP%" >nul 2>nul&&set online=1
goto :eof