@echo off
:Main
setlocal EnableDelayedExpansion
call :ShowInputIP
call :CheckIP
if %errorlevel% == 1 (
call :TrackIP !IP! 1
)
setlocal DisableDelayedExpansion
goto :Main
::---------------------------------------------------------------
:TrackIP
ping %1 -n 2 -i %2 >rs.txt
set /a c=%2+1
if %c% geq 65 (
echo 超出TTL限制[65]
ping %1 -n 1
goto :eof
)
for /f "tokens=1-5* delims= " %%i in (rs.txt) do (
if "%%i" == "来自" (
echo 追踪到IP[%%j] TTL=%2
if %%j == !IP! (
echo 追踪完成!!!
) else (
call :TrackIP %1 %c%
)
goto :eof
) else (
if "%%i" == "请求超时。" (
echo 跳跃TTL [TTL=%2%]
call :TrackIP %1 %c%
goto :eof
)
)
)
goto :eof
::---------------------------------------------------------------
:ShowInputIP
echo 请输入要跟踪 ip/域名 地址:
set /p IP=
goto :eof
::---------------------------------------------------------------
:CheckIP
ping %IP% -n 1 >temp.txt
set context=
for /f "tokens=1-5* delims= " %%i in (temp.txt) do (
if "%%m" == "具有" (
set context=%%l
set IP=!context:~1,-1!
echo 解析域名 [%IP%] → IP [!IP!]
goto :CheckEnd
)
)
:CheckEnd
del temp.txt
exit /b 1