Board logo

标题: 如何使用返回结果作为分析变量? [打印本页]

作者: senffon     时间: 2010-5-9 12:22    标题: 如何使用返回结果作为分析变量?

目的:通过连续ping 一组主机,然后从PING返回结果中记录下网络丢包的时间和PING 值廷时超过200的发生时间

文件HOSTIP.txt内容:
qq.com
114la.com
hao123.com
192.168.0.254

文件pingtest.cmd内容:
CODE:  [Copy to clipboard]
setlocal EnableDelayedExpansion
@mode con cols=80 lines=25
@color 0b
@echo off

:loop
set ip=qq.com
set ip2=114la.com
set ip3=hao123.com
call :sping %ip%
call :sping %ip2%
call :sping %ip3%
goto loop

:sping
title 检测到 %1 连接信息
echo.=========================================================================
ping -n 1 %1 |find /i "TTL"
if %errorlevel% == 0 (echo.在【%date% %time%】时测试到 %1 网络是连通的) else (
echo. 在【%date% %time%】时测试到 %1 网络不通>>lost.log)
[ Last edited by senffon on 2010-5-9 at 13:41 ]
作者: yonghu111     时间: 2010-5-9 12:59
if %errorlevel%=0 为 if %errorlevel%==0 吧!
作者: yonghu111     时间: 2010-5-9 13:15
楼主还多了最后一个括号!!
作者: senffon     时间: 2010-5-9 13:48
CODE:  [Copy to clipboard]
@mode con cols=80 lines=25
@color 0b
@echo off
setlocal EnableDelayedExpansion

:loop
for /f %%a in (hostip.txt) do (
        set ipadd=%%a
        title 检测到 !ipadd! 连接信息
        echo. 在时间:%date% %time:~0,5% 测试到 !ipadd!:
        ping -n 1 !ipadd!|find /i "TTL"
        echo.=============================================================================
        if %errorlevel% == 1 echo. 在【%date% %time%】时测试到 !ipadd! 网络不通>>lost.log
       
)
goto loop

作者: senffon     时间: 2010-5-9 13:50
如何才能把同一时间PING 返回结果中 reply From 条目 和 time out 分离并输出到日志呢?

注意是,同一时间点执行的同一次命令!

[ Last edited by senffon on 2010-5-9 at 13:52 ]
作者: Hanyeguxing     时间: 2010-5-9 15:19
for /f解析ping 命令




欢迎光临 中国DOS联盟论坛 (http://cndos.fam.cx/forum/) Powered by Discuz! 2.5