Chinaunix

标题: 如何在ping 命令结果前面加上时间日期!!! [打印本页]

作者: jhgzzq    时间: 2005-09-09 13:01
标题: 如何在ping 命令结果前面加上时间日期!!!
我现在打算测试一个网络是否正常.要观察几天.打算用ping的方式检查.

但只有下面的显示:

Pinging 10.111.23.1 with 32 bytes of data:

Reply from 10.111.23.1 : bytes=32 time=2ms TTL=255
Reply from 10.111.23.1 : bytes=32 time=2ms TTL=255
Reply from 10.111.23.1 : bytes=32 time=1ms TTL=255

无法定位是在哪个时间里出现的.我想在前面加上时间如:

Pinging 10.111.23.1 with 32 bytes of data:

2005-09-09 00:00:00 Reply from 10.111.23.1 : bytes=32 time=2ms TTL=255
2005-09-09 00:00:01 Reply from 10.111.23.1 : bytes=32 time=2ms TTL=255
2005-09-09 00:00:02 Reply from 10.111.23.1 : bytes=32 time=1ms TTL=255

哪位大侠知道bat的批处理该如何实现?
作者: archangle    时间: 2005-09-09 13:31
标题: 如何在ping 命令结果前面加上时间日期!!!
我有一个笨办法
while [ 1 ];do
date;ping ip -c 1
done
作者: jhgzzq    时间: 2005-09-09 13:55
标题: 如何在ping 命令结果前面加上时间日期!!!
while [ 1 ];do
date;ping ip -c 1
done

这个写在bat里是无法执行的吧.能否具体点呢
作者: jhgzzq    时间: 2005-09-09 16:39
标题: 如何在ping 命令结果前面加上时间日期!!!
怎么没有人回复哟.....
作者: archangle    时间: 2005-09-09 16:46
标题: 如何在ping 命令结果前面加上时间日期!!!
while [ 1 ];do
date;ping ip -c 1
done

这个写在bat里是无法执行的吧.能否具体点呢

我以为你是linux系统。
很久没碰dos了。帮不了你。
作者: AmoyOriole    时间: 2005-09-13 17:45
标题: 如何在ping 命令结果前面加上时间日期!!!
@echo off
:START
date/t >> aa.txt
time/t >> aa.txt
ping 10.111.23.1 -n 10 >>aa.txt
goto START

稍微变通的方法,呵呵。

[ 本帖最后由 AmoyOriole 于 2006-4-4 08:57 编辑 ]
作者: jhgzzq    时间: 2005-09-13 19:10
标题: 如何在ping 命令结果前面加上时间日期!!!
谢谢:AmoyOriole

不过这种格式打印出来的结果时间怎么一直不变呢?是语句哪里有问题?

2005-09-13 星期二
19:09

Pinging 134.230.55.1 with 32 bytes of data:

Reply from 134.230.55.1: bytes=32 time=2ms TTL=255
Reply from 134.230.55.1: bytes=32 time=2ms TTL=255
Reply from 134.230.55.1: bytes=32 time=2ms TTL=255

Ping statistics for 134.230.55.1:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 2ms, Maximum = 2ms, Average = 2ms
2005-09-13 星期二
19:09

Pinging 134.230.55.1 with 32 bytes of data:

Reply from 134.230.55.1: bytes=32 time=2ms TTL=255
Reply from 134.230.55.1: bytes=32 time=3ms TTL=255
Reply from 134.230.55.1: bytes=32 time=2ms TTL=255

Ping statistics for 134.230.55.1:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 2ms, Maximum = 3ms, Average = 2ms
2005-09-13 星期二
19:09

Pinging 134.230.55.1 with 32 bytes of data:

Reply from 134.230.55.1: bytes=32 time=2ms TTL=255

Ping statistics for 134.230.55.1:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 2ms, Maximum = 2ms, Average = 2ms
作者: SuperCube    时间: 2005-09-14 10:09
标题: 如何在ping 命令结果前面加上时间日期!!!
time/t只精确到分钟。
改成ehco. |time >;>; aa.txt 就可以了。
作者: 4℃華客    时间: 2005-09-14 10:42
标题: 如何在ping 命令结果前面加上时间日期!!!
谢谢了,我又学到了一些东西!
作者: slash001    时间: 2005-09-14 12:03
标题: 如何在ping 命令结果前面加上时间日期!!!

  1. Set shell = WScript.CreateObject("WScript.Shell")
  2. Set re=New RegExp
  3. re.Pattern = "^Reply|^Request"
  4. Set myping=shell.Exec("ping 192.168.0.249")
  5. while Not myping.StdOut.AtEndOfStream
  6.         strLine = myping.StdOut.ReadLine()
  7.         r=re.Test(strLine)
  8.         If r Then
  9.                 WScript.Echo date & " "& time & chr(9) & strLine
  10.         End if
  11. Wend
复制代码


保存成tping.vbs
在command下执行cscript tping.vbs

输出结果
2005-9-14 12:02:01      Reply from 192.168.0.249: bytes=32 time<10ms TTL=64
2005-9-14 12:02:02      Reply from 192.168.0.249: bytes=32 time<10ms TTL=64
2005-9-14 12:02:03      Reply from 192.168.0.249: bytes=32 time<10ms TTL=64
2005-9-14 12:02:04      Reply from 192.168.0.249: bytes=32 time<10ms TTL=64
作者: joefun    时间: 2005-09-19 07:37
标题: 如何在ping 命令结果前面加上时间日期!!!
slash001 GG的脚本的确8错!   
作者: carrison    时间: 2005-09-19 09:52
标题: 如何在ping 命令结果前面加上时间日期!!!
还是vbs功能强大,呵呵,谁用perl来一个?
作者: slash001    时间: 2005-09-19 11:25
标题: 如何在ping 命令结果前面加上时间日期!!!
perl的代码

  1. #!/usr/bin/perl
  2. open(PING, "ping 192.168.0.249|");
  3. while (<PING>)
  4. {
  5.         if ($_ =~ /^Reply|^Request/)
  6.         {
  7.                 my @date=localtime(time);
  8.                 printf("%d-%02d-%02d %02d:%02d:%02d %s", $date[5]+1900, $date[4]+1, $date[3], $date[2], $date[1], $date[0], $_);
  9.         }
  10. }
  11. close(PING);
复制代码

[ 本帖最后由 slash001 于 2005-11-15 11:41 编辑 ]
作者: b.s.d    时间: 2005-09-19 17:50
标题: 如何在ping 命令结果前面加上时间日期!!!
C:\>;cscript tping.vbs
Microsoft (R) Windows 脚本宿主版本 5.1 for Windows
版权所有(C) Microsoft Corporation 1996-1999. All rights reserved.

C:\tping.vbs(4, 1) Microsoft VBScript 运行时错误: 对象不支持此属性或方法: 'shell
.Exec'
作者: slash001    时间: 2005-09-19 18:20
标题: 如何在ping 命令结果前面加上时间日期!!!
我是在Win2000下测试的
Microsoft (R) Windows Script Host Version 5.6
作者: carrison    时间: 2005-09-20 08:41
标题: 如何在ping 命令结果前面加上时间日期!!!
[quote]原帖由 "slash001"][/quote 发表:


难不住你了,老弟再用C写一个?哈哈
作者: carrison    时间: 2005-09-20 08:44
标题: 如何在ping 命令结果前面加上时间日期!!!
XP下也没问题
C:\>;cscript pt.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

2005-9-20 8:43:21       Reply from 10.20.33.3: bytes=32 time=1ms TTL=64
2005-9-20 8:43:22       Reply from 10.20.33.3: bytes=32 time<1ms TTL=64
2005-9-20 8:43:23       Reply from 10.20.33.3: bytes=32 time<1ms TTL=64
2005-9-20 8:43:24       Reply from 10.20.33.3: bytes=32 time<1ms TTL=64

Perl下也不错
C:\>;perl pt2.pl
2005-09-20 09:08:32 Reply from 10.20.33.3: bytes=32 time=1ms TTL=64
2005-09-20 09:08:33 Reply from 10.20.33.3: bytes=32 time<1ms TTL=64
2005-09-20 09:08:34 Reply from 10.20.33.3: bytes=32 time=1ms TTL=64
2005-09-20 09:08:35 Reply from 10.20.33.3: bytes=32 time<1ms TTL=64
作者: 剑心通明    时间: 2005-09-20 09:22
标题: 如何在ping 命令结果前面加上时间日期!!!
收藏,不错不错
作者: b.s.d    时间: 2005-09-20 09:32
标题: 如何在ping 命令结果前面加上时间日期!!!
[quote="b.s.d"]C:\>;cscript tping.vbs
Microsoft (R) Windows 脚本宿主版本 5.1 for Windows
版权所有(C) Microsoft Corporation 1996-1999. All rights reserved.

C:\tping.vbs(4, 1) Microsoft VBScript 运行时错误: 对?.........[/quote]
我的是2003
作者: slash001    时间: 2005-09-20 10:11
标题: 如何在ping 命令结果前面加上时间日期!!!
C不怎么用,随便写了一个,呵呵
Win2000 Cygwin下编译测试通过

  1. #include <stdio.h>;
  2. #include <string.h>;
  3. #include <time.h>;

  4. int main(int argc, char *argv[])
  5. {
  6.         time_t clock;
  7.         struct tm *tm;       
  8.         char tbuf[20];

  9.         FILE *res;
  10.         char buf[256];
  11.         res=popen("ping 192.168.0.249", "r");

  12.         while (fgets(buf, sizeof(buf), res))
  13.         {
  14.                 if (bcmp(buf, "Reply", 5) == 0 || bcmp(buf, "Request", 7) == 0)
  15.                 {
  16.                         time(&clock);
  17.                         tm=localtime(&clock );
  18.                         strftime(tbuf, 20, "%Y-%m-%d %H:%M:%S", tm);
  19.                         printf("%s\t%s", tbuf, buf);
  20.                 }
  21.         }
  22.         pclose(res);
  23.         return 0;
  24. }
复制代码

作者: slash001    时间: 2005-09-20 10:40
标题: 如何在ping 命令结果前面加上时间日期!!!
原帖由 "b.s.d" 发表:

我的是2003

将Windows脚本宿主升级到5.6试试
作者: carrison    时间: 2005-09-20 12:29
标题: 如何在ping 命令结果前面加上时间日期!!!
[quote]原帖由 "slash001"][/quote 发表:

unix下C编程也会,老弟全才啊, 就差Java的了
你让俺看到了中国软件的希望啊,哈哈
作者: slash001    时间: 2005-09-20 13:23
标题: 如何在ping 命令结果前面加上时间日期!!!
呵呵,我不是做开发的,就会简单的瞎写点,见笑了
作者: carrison    时间: 2005-09-20 13:50
标题: 如何在ping 命令结果前面加上时间日期!!!
呵呵,做管理的都会瞎写点就很难得了
作者: platinum    时间: 2005-09-20 15:25
标题: 如何在ping 命令结果前面加上时间日期!!!
如果是在 Linux 下面,可以这样

  1. # while :;do ping -c 1 172.17.39.251|awk '/ttl=/'|sed "s/^/`date +%Y-%m-%d\|%T` /";sleep 1;done
复制代码



显示效果如下
[root@PT_LINUX boot]# while :;do ping -c 1 172.17.39.251|awk '/ttl=/'|sed "s/^/`date +%Y-%m-%d\|%T` /";sleep 1;done
2005-09-20|15:24:40 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.240 ms
2005-09-20|15:24:41 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.235 ms
2005-09-20|15:24:42 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.220 ms
2005-09-20|15:24:43 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.224 ms
2005-09-20|15:24:45 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.211 ms
2005-09-20|15:24:46 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.211 ms
2005-09-20|15:24:47 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.222 ms
2005-09-20|15:24:48 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.221 ms
2005-09-20|15:24:49 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.222 ms

[root@PT_LINUX boot]#

作者: 无心。有心    时间: 2005-09-26 08:48
标题: 如何在ping 命令结果前面加上时间日期!!!
我想请问一下为什么在我的机子上这个命令不行呢
作者: Hex    时间: 2005-09-26 23:27
标题: 如何在ping 命令结果前面加上时间日期!!!
[quote]原帖由 "slash001"][/quote 发表:


cool!
作者: ioiioi    时间: 2005-09-28 22:09
标题: 如何在ping 命令结果前面加上时间日期!!!
哪位高手可以将tping.vbs更改一下,可以自己设定ip和一些参数?
比如cscript tping.vbs 192.168.1.1 -t -l 1000
那就完美了。
作者: slash001    时间: 2005-09-30 10:01
标题: 如何在ping 命令结果前面加上时间日期!!!

  1. Dim args, flag, unsuccOut
  2. args=""
  3. otherout=""
  4. flag=0

  5. If WScript.Arguments.count = 0 Then
  6.         WScript.Echo "Usage: cscript tping.vbs [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]"
  7.         WScript.Echo "                         [-s count] [[-j host-list] | [-k host-list]]"
  8.         WScript.Echo "                         [-r count] [-w timeout] destination-list"
  9.         wscript.quit
  10. End if

  11. For i=0 to WScript.Arguments.count - 1
  12.         args=args & " " & WScript.Arguments(i)
  13. Next

  14. Set shell = WScript.CreateObject("WScript.Shell")
  15. Set re=New RegExp
  16. re.Pattern="^Reply|^Request"
  17. Set myping=shell.Exec("ping" & args)

  18. while Not myping.StdOut.AtEndOfStream
  19.    strLine=myping.StdOut.ReadLine()
  20.    r=re.Test(strLine)
  21.    If r Then
  22.         WScript.Echo date & " "& time & chr(9) & strLine
  23.         flag=1
  24.    Else
  25.         unsuccOut=unsuccOut & strLine
  26.    End if
  27. Wend

  28. if flag = 0 then
  29.         WScript.Echo unsuccOut
  30. end if
复制代码


E:\>;cscript tping.vbs 192.168.0.249 -t -l 1000
Microsoft (R) Windows Script Host Version 5.6
版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。

2005-9-30 10:03:29      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64
2005-9-30 10:03:30      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64
2005-9-30 10:03:31      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64
2005-9-30 10:03:32      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64
2005-9-30 10:03:33      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64
2005-9-30 10:03:34      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64
2005-9-30 10:03:35      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64
2005-9-30 10:03:36      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64
作者: liutongzhu    时间: 2005-10-08 16:13
标题: 如何在ping 命令结果前面加上时间日期!!!
   
zzzzzz
作者: 可观    时间: 2005-10-09 09:54
标题: 如何在ping 命令结果前面加上时间日期!!!
收藏,不错。
作者: xuesp001    时间: 2005-10-10 09:51
标题: 如何在ping 命令结果前面加上时间日期!!!
slash001的方法很不错罗!
作者: mzd73    时间: 2005-10-10 09:55
标题: 如何在ping 命令结果前面加上时间日期!!!
好办法
作者: plumlee    时间: 2005-10-15 13:51
标题: 如何在ping 命令结果前面加上时间日期!!!
slash001
你在CU才发了不够30帖,帖帖都精华呀~!!!
作者: asd2004    时间: 2005-10-15 15:13
标题: 如何在ping 命令结果前面加上时间日期!!!
太COOL了, slash001  你就是我的偶像啊!!
作者: xiaaifei    时间: 2005-10-15 18:25
提示: 作者被禁止或删除 内容自动屏蔽
作者: Rcfeng    时间: 2005-10-16 03:36
提示: 作者被禁止或删除 内容自动屏蔽
作者: plumlee    时间: 2005-10-20 16:56
标题: 如何在ping 命令结果前面加上时间日期!!!
今天试了。可以引入到excel中做成曲线图~~
作者: excellent    时间: 2005-11-03 16:30
原帖由 AmoyOriole 于 2005-9-13 17:45 发表
@echo off
:START
date/t >;>; aa.txt
time/t >;>; aa.txt
ping 10.111.23.1 -n 10 >;>;aa.txt
goto START

稍微变通的方法,呵呵。



问一下 ">;>; " 是什么意思呢??
作者: rainballdh    时间: 2005-11-04 19:31
原帖由 archangle 于 2005-9-9 13:31 发表
我有一个笨办法
while [ 1 ];do
date;ping ip -c 1
done

这个怎么运行呀?
作者: rainballdh    时间: 2005-11-04 19:32
知道料,直接在终端运行
作者: xyco    时间: 2005-11-05 09:23
强啊!收起
作者: zhxf_1    时间: 2005-11-09 15:13
楼上的,语法好象有点问题啊 !
作者: webcup    时间: 2005-11-09 20:50
CreateObject&#40

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:ping.vbs(1, 34) Microsoft VBScript compilation error: Syntax error
作者: sun-bone    时间: 2006-03-20 18:44
标题: 呵呵!麻烦还能不能加一个小功能了
在cmd下使用ping的命令长ping一个地址时,中途可以使用“Ctrl”+“Break”组合键中断一下ping,只是显示从开始ping到你发指令这一时间段的ping的情况,能不能把这个组合键的功能也加进去
作者: lzl0310lzl    时间: 2006-03-23 16:18

作者: 馒头血案    时间: 2006-03-25 02:35
呵呵。
作者: inhell    时间: 2006-03-27 11:04
强帖留名
作者: ainimeiban    时间: 2006-03-28 22:41
XP下如何运行那个..
作者: xyzzyu    时间: 2011-07-21 23:28
windows server 2008下边 执行不成功呀,高手能不能帮忙分析下
作者: 飞檐走壁的人    时间: 2011-07-23 13:28
提示: 作者被禁止或删除 内容自动屏蔽
作者: minnieniu    时间: 2011-08-09 16:33
真好,学习了
作者: icyomik    时间: 2011-11-13 13:25
我来一个简单的:
while true; do echo `date` $(ping -c 1 g.cn |grep "^64 bytes from"); sleep 1; done
如果想后台写到文件中:(或者你会需要记下其PID)
while true; do echo `date` $(ping -c 1 g.cn |grep "^64 bytes from") >>/tmp/ping.log; sleep 1; done &
作者: 仇若涵    时间: 2012-04-19 11:06
强人,三分,不时来D
作者: ulovko    时间: 2012-04-21 18:21
原来是WINDOWS 我也不会,LINUX 还会点!
作者: linllian8    时间: 2014-09-05 15:49
这个貌似执行不成功啊,高手解决下,执行后,没有包显示

Dim args, flag, unsuccOut
args=""
otherout=""
flag=0

If WScript.Arguments.count = 0 Then
        WScript.Echo "Usage: cscript tping.vbs [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]"
        WScript.Echo "                         [-s count] [[-j host-list] | [-k host-list]]"
        WScript.Echo "                         [-r count] [-w timeout] destination-list"
        wscript.quit
End if

For i=0 to WScript.Arguments.count - 1
        args=args & " " & WScript.Arguments(i)
Next

Set shell = WScript.CreateObject("WScript.Shell")
Set re=New RegExp
re.Pattern="^Reply|^Request"
Set myping=shell.Exec("ping" & args)

while Not myping.StdOut.AtEndOfStream
   strLine=myping.StdOut.ReadLine()
   r=re.Test(strLine)
   If r Then
        WScript.Echo date & " "& time & chr(9) & strLine
        flag=1
   Else
        unsuccOut=unsuccOut & strLine
   End if
Wend

if flag = 0 then
        WScript.Echo unsuccOut
end if


作者: Henry9021    时间: 2015-09-02 12:33
本帖最后由 Henry9021 于 2015-09-02 15:30 编辑

牛人!!   为什么 我运行之后没有反应啊!



E:\>;cscript pt1.vbs 192.168.1.1 -t
Microsoft (R) Windows Script Host Version 5.8
版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。

Ping 请求找不到主机 ping。请检查该名称,然后重试。

E:\>ping 192.168.1.1

正在 Ping 192.168.1.1 具有 32 字节的数据:
来自 192.168.1.1 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.1.1 的回复: 字节=32 时间<1ms TTL=64

192.168.1.1 的 Ping 统计信息:
    数据包: 已发送 = 2,已接收 = 2,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms
Control-C
^C
E:\>;cscript pt1.vbs ping 192.168.1.1 -t
Microsoft (R) Windows Script Host Version 5.8
版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。

Ping 请求找不到主机 ping。请检查该名称,然后重试。

E:\>
作者: Henry9021    时间: 2015-09-02 15:31
XP的可以  WIN7的不行....... 回复 58# Henry9021


   
作者: 天涯风飓    时间: 2015-09-09 21:10
来支持呢。。。
作者: 下沙开发区    时间: 2015-09-10 19:24
来看看的哦。。。。。。。。。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2