Board logo

标题: [网络连接] 批处理如何提取ping某个主机返回结果中延迟时间/响应时间大于5ms的行数据? [打印本页]

作者: 不点饣    时间: 2016-5-12 11:12     标题: 批处理如何提取ping某个主机返回结果中延迟时间/响应时间大于5ms的行数据?

本帖最后由 pcl_test 于 2016-5-12 12:54 编辑

请教大家,怎么提取ping一个地址里面的  time大于5ms的行记录到TXT里。最好是可以加上时间!

Pinging www.a.shifen.com [14.215.177.37] with 32 bytes of data:
Reply from 14.215.177.37: bytes=32 time=5ms TTL=56
Reply from 14.215.177.37: bytes=32 time=5ms TTL=56
Reply from 14.215.177.37: bytes=32 time=8ms TTL=56
Reply from 14.215.177.37: bytes=32 time=10ms TTL=56


Ping statistics for 14.215.177.37:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 5ms, Maximum = 5ms, Average = 5ms
作者: flyinnet9    时间: 2016-5-12 14:09

  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. for /f "tokens=1-7* delims== " %%a in ('ping  www.a.shifen.com^|find /i "Reply"') do (
  4.   set str=%%g
  5.   set str=!str:ms=!
  6.   if !str! gtr 5 echo.%%a %%b %%c %%d=%%e %%f=%%g %%h
  7. )
  8. pause
复制代码

作者: pcl_test    时间: 2016-5-12 19:44

  1. ping www.a.shifen.com|findstr /r /c:"time=[6-9]ms" /c:"time=[1-9][0-9][0-9]*ms"
  2. pause
复制代码

作者: 不点饣    时间: 2016-5-13 09:47

谢谢 各位! 已解决!
作者: ygqiang    时间: 2016-5-13 11:18

回复 4# 不点饣


    如何解决的?
作者: yujw668    时间: 2019-6-13 10:33

怎么解决的?能告知一下吗?
  1. ping www.a.shifen.com|findstr /r /c:"time=[6-9]ms" /c:"time=[1-9][0-9][0-9]*ms"
  2. pause
复制代码
后面的time=[1-9][0-9][0-9]*ms 这个是搜索什么呢?
作者: Batcher    时间: 2019-6-13 11:43

回复 6# yujw668


    搜索的是大于等于10ms的情况
作者: yujw668    时间: 2019-6-13 15:53

  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. for /f "tokens=1-7* delims== " %%a in ('ping www.a.shifen.com  ^|findstr /r /c:"时间=[0-9]ms" /c:"时间=[1-9][0-9][0-9]*ms"
  4. ') do (
  5.   set str=%%g
  6.   set str=!str:ms=!
  7.     if !str! gtr 3 echo.%date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%a %%b %%c %%d=%%e %%f=%%g %%h>>wenti.txt
  8. if !str! gtr 3 echo.%date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%a %%b %%c %%d=%%e %%f=%%g %%h
  9. )
  10. pause
复制代码
问题1、就是想一直ping ,加上-t参数之后就运行不了起来了。
问题2、/c:"时间=[1-9][0-9][0-9]*ms  "*"是什么意思?搜索大于10毫秒是不是不用“*”号?
作者: Batcher    时间: 2019-6-13 16:14

回复 8# yujw668


搜索大于10毫秒是不是不用“*”号?

你可以去掉*号试验一下能否正确的匹配到几十秒、几百秒、几千秒等情况,如果可以,那就不用*号。
作者: Batcher    时间: 2019-6-13 16:18

回复 8# yujw668


for循环命令要得到 ping xxx | findstr xxx 得到的结果才能进行处理
ping -t 会不停的执行,导致for命令无法获取结果进行后续处理




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2