运行截图

liang23_20220815201704.jpg

文件链接

https://pan.runyf.cn/bat/monitor.bat

源代码展示

@echo off
@title 主机监控
:: by: www.runyf.cn

:: 等待用户输入需要监控IP
set /p ip=请输入IP地址:
:: 请求等待秒数
set waits=1

:: 如果输入0就删除缓存并退出
if %ip% == 0 (
    del *.iptmp 
    exit
) 

:: 设置回显时间格式
set file=%ip%-%date:~0,4%%date:~5,2%%date:~8,2%.txt
set echotime=%date:~0,4%%date:~5,2%%date:~8,2% %time%
echo %echotime% 目标地址:%ip% 脚本开始执行... 
echo %echotime%  目标地址:%ip% 脚本开始执行... >> %file%

:start
@title 主机监控 %ip%

:: 设置文件名
set file=%ip%-%date:~0,4%%date:~5,2%%date:~8,2%.txt
set tmpfile=%file%.iptmp


:: 更新时间
set echotime=%date:~0,4%%date:~5,2%%date:~8,2% %time%

:: 进行ping测试
echo|set /p =%echotime% >%tmpfile%
ping -n 1 %ip% | findstr /i "来自 一般 超时">>%tmpfile%

:: 回显
findstr 2 %tmpfile%>>%file% 
findstr 2 %tmpfile%

:: 等待
timeout /t %waits% > nul

goto start
最后修改:2022 年 10 月 26 日
如果觉得我的文章对你有用,请随意赞赏