新版icmp监控

@echo off

set ip=192.168.6.156
set waits=1
set log=log_icmPing.txt


:main
echo %date% %time% >> %log%
ping -n 1 %ip% | findstr /i "来自 一般 超时 失败">>%log%
timeout /t %waits%
goto main

主机tcp端口监控

@echo off

set ip=192.168.6.156
set port=3389
set waits=1
set log=log_portPing.txt



:main
echo %date% %time% >> %log%
tcping -n 1 %ip% %port%  | find "Probing" >> %log%
timeout /t %waits%
goto main

旧版本icmp监控

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

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

:: 删除缓存
del *.iptmp 

:: 设置回显时间格式
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
最后修改:2023 年 11 月 15 日
如果觉得我的文章对你有用,请随意赞赏