Chinaunix

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

作者: jhgzzq    时间: 2005-09-09 13:01
标题: 如何在ping 命令结果前面加上时间日期!!!
我现在打算测试一个网络是否正常.要观察几天.打算用ping的方式检查.\r\n\r\n但只有下面的显示:\r\n\r\nPinging 10.111.23.1 with 32 bytes of data:\r\n\r\nReply from 10.111.23.1 : bytes=32 time=2ms TTL=255\r\nReply from 10.111.23.1 : bytes=32 time=2ms TTL=255\r\nReply from 10.111.23.1 : bytes=32 time=1ms TTL=255\r\n\r\n无法定位是在哪个时间里出现的.我想在前面加上时间如:\r\n\r\nPinging 10.111.23.1 with 32 bytes of data:\r\n\r\n2005-09-09 00:00:00 Reply from 10.111.23.1 : bytes=32 time=2ms TTL=255\r\n2005-09-09 00:00:01 Reply from 10.111.23.1 : bytes=32 time=2ms TTL=255\r\n2005-09-09 00:00:02 Reply from 10.111.23.1 : bytes=32 time=1ms TTL=255\r\n\r\n哪位大侠知道bat的批处理该如何实现?
作者: archangle    时间: 2005-09-09 13:31
标题: 如何在ping 命令结果前面加上时间日期!!!
我有一个笨办法\r\nwhile [ 1 ];do\r\ndate;ping ip -c 1\r\ndone
作者: jhgzzq    时间: 2005-09-09 13:55
标题: 如何在ping 命令结果前面加上时间日期!!!
while [ 1 ];do \r\ndate;ping ip -c 1 \r\ndone\r\n\r\n这个写在bat里是无法执行的吧.能否具体点呢
作者: jhgzzq    时间: 2005-09-09 16:39
标题: 如何在ping 命令结果前面加上时间日期!!!
怎么没有人回复哟.....
作者: archangle    时间: 2005-09-09 16:46
标题: 如何在ping 命令结果前面加上时间日期!!!
\r\nwhile [ 1 ];do\r\ndate;ping ip -c 1\r\ndone\r\n\r\n这个写在bat里是无法执行的吧.能否具体点呢\r\n
\r\n我以为你是linux系统。\r\n很久没碰dos了。帮不了你。
作者: AmoyOriole    时间: 2005-09-13 17:45
标题: 如何在ping 命令结果前面加上时间日期!!!
@echo off\r\n:START\r\ndate/t >> aa.txt\r\ntime/t >> aa.txt\r\nping 10.111.23.1 -n 10 >>aa.txt\r\ngoto START\r\n\r\n稍微变通的方法,呵呵。\n\n[ 本帖最后由 AmoyOriole 于 2006-4-4 08:57 编辑 ]
作者: jhgzzq    时间: 2005-09-13 19:10
标题: 如何在ping 命令结果前面加上时间日期!!!
谢谢:AmoyOriole\r\n\r\n不过这种格式打印出来的结果时间怎么一直不变呢?是语句哪里有问题?\r\n\r\n2005-09-13 星期二 \r\n19:09\r\n\r\nPinging 134.230.55.1 with 32 bytes of data:\r\n\r\nReply from 134.230.55.1: bytes=32 time=2ms TTL=255\r\nReply from 134.230.55.1: bytes=32 time=2ms TTL=255\r\nReply from 134.230.55.1: bytes=32 time=2ms TTL=255\r\n\r\nPing statistics for 134.230.55.1:\r\n    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n    Minimum = 2ms, Maximum = 2ms, Average = 2ms\r\n2005-09-13 星期二 \r\n19:09\r\n\r\nPinging 134.230.55.1 with 32 bytes of data:\r\n\r\nReply from 134.230.55.1: bytes=32 time=2ms TTL=255\r\nReply from 134.230.55.1: bytes=32 time=3ms TTL=255\r\nReply from 134.230.55.1: bytes=32 time=2ms TTL=255\r\n\r\nPing statistics for 134.230.55.1:\r\n    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n    Minimum = 2ms, Maximum = 3ms, Average = 2ms\r\n2005-09-13 星期二 \r\n19:09\r\n\r\nPinging 134.230.55.1 with 32 bytes of data:\r\n\r\nReply from 134.230.55.1: bytes=32 time=2ms TTL=255\r\n\r\nPing statistics for 134.230.55.1:\r\n    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),\r\nApproximate round trip times in milli-seconds:\r\n    Minimum = 2ms, Maximum = 2ms, Average = 2ms
作者: SuperCube    时间: 2005-09-14 10:09
标题: 如何在ping 命令结果前面加上时间日期!!!
time/t只精确到分钟。\r\n改成ehco. |time >;>; aa.txt 就可以了。
作者: 4℃華客    时间: 2005-09-14 10:42
标题: 如何在ping 命令结果前面加上时间日期!!!
谢谢了,我又学到了一些东西!
作者: slash001    时间: 2005-09-14 12:03
标题: 如何在ping 命令结果前面加上时间日期!!!
  1. \r\nSet shell = WScript.CreateObject(\"WScript.Shell\")\r\nSet re=New RegExp\r\nre.Pattern = \"^Reply|^Request\"\r\nSet myping=shell.Exec(\"ping 192.168.0.249\")\r\nwhile Not myping.StdOut.AtEndOfStream\r\n        strLine = myping.StdOut.ReadLine()\r\n        r=re.Test(strLine)\r\n        If r Then\r\n                WScript.Echo date & \" \"& time & chr(9) & strLine\r\n        End if\r\nWend\r\n
复制代码
\r\n\r\n保存成tping.vbs\r\n在command下执行cscript tping.vbs\r\n\r\n输出结果\r\n2005-9-14 12:02:01      Reply from 192.168.0.249: bytes=32 time<10ms TTL=64\r\n2005-9-14 12:02:02      Reply from 192.168.0.249: bytes=32 time<10ms TTL=64\r\n2005-9-14 12:02:03      Reply from 192.168.0.249: bytes=32 time<10ms TTL=64\r\n2005-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的代码\r\n
  1. \r\n#!/usr/bin/perl\r\nopen(PING, \"ping 192.168.0.249|\");\r\nwhile (<PING>)\r\n{\r\n        if ($_ =~ /^Reply|^Request/)\r\n        {\r\n                my @date=localtime(time);\r\n                printf(\"%d-%02d-%02d %02d:%02d:%02d %s\", $date[5]+1900, $date[4]+1, $date[3], $date[2], $date[1], $date[0], $_);\r\n        }\r\n}\r\nclose(PING);\r\n
复制代码
\n\n[ 本帖最后由 slash001 于 2005-11-15 11:41 编辑 ]
作者: b.s.d    时间: 2005-09-19 17:50
标题: 如何在ping 命令结果前面加上时间日期!!!
C:\\>;cscript tping.vbs\r\nMicrosoft (R) Windows 脚本宿主版本 5.1 for Windows\r\n版权所有(C) Microsoft Corporation 1996-1999. All rights reserved.\r\n\r\nC:\\tping.vbs(4, 1) Microsoft VBScript 运行时错误: 对象不支持此属性或方法: \'shell\r\n.Exec\'
作者: slash001    时间: 2005-09-19 18:20
标题: 如何在ping 命令结果前面加上时间日期!!!
我是在Win2000下测试的\r\nMicrosoft (R) Windows Script Host Version 5.6
作者: carrison    时间: 2005-09-20 08:41
标题: 如何在ping 命令结果前面加上时间日期!!!
[quote]原帖由 \"slash001\"][/quote 发表:\n\r\n\r\n难不住你了,老弟再用C写一个?哈哈
作者: carrison    时间: 2005-09-20 08:44
标题: 如何在ping 命令结果前面加上时间日期!!!
XP下也没问题\r\nC:\\>;cscript pt.vbs\r\nMicrosoft (R) Windows Script Host Version 5.6\r\nCopyright (C) Microsoft Corporation 1996-2001. All rights reserved.\r\n\r\n2005-9-20 8:43:21       Reply from 10.20.33.3: bytes=32 time=1ms TTL=64\r\n2005-9-20 8:43:22       Reply from 10.20.33.3: bytes=32 time<1ms TTL=64\r\n2005-9-20 8:43:23       Reply from 10.20.33.3: bytes=32 time<1ms TTL=64\r\n2005-9-20 8:43:24       Reply from 10.20.33.3: bytes=32 time<1ms TTL=64\r\n\r\nPerl下也不错\r\nC:\\>;perl pt2.pl\r\n2005-09-20 09:08:32 Reply from 10.20.33.3: bytes=32 time=1ms TTL=64\r\n2005-09-20 09:08:33 Reply from 10.20.33.3: bytes=32 time<1ms TTL=64\r\n2005-09-20 09:08:34 Reply from 10.20.33.3: bytes=32 time=1ms TTL=64\r\n2005-09-20 09:08:35 Reply from 10.20.33.3: bytes=32 time<1ms TTL=64
作者: b.s.d    时间: 2005-09-20 09:32
标题: 如何在ping 命令结果前面加上时间日期!!!
[quote=\"b.s.d\"]C:\\>;cscript tping.vbs\r\nMicrosoft (R) Windows 脚本宿主版本 5.1 for Windows\r\n版权所有(C) Microsoft Corporation 1996-1999. All rights reserved.\r\n\r\nC:\\tping.vbs(4, 1) Microsoft VBScript 运行时错误: 对?.........[/quote]\r\n我的是2003
作者: slash001    时间: 2005-09-20 10:11
标题: 如何在ping 命令结果前面加上时间日期!!!
C不怎么用,随便写了一个,呵呵\r\nWin2000 Cygwin下编译测试通过\r\n
  1. \r\n#include <stdio.h>;\r\n#include <string.h>;\r\n#include <time.h>;\r\n\r\nint main(int argc, char *argv[])\r\n{\r\n        time_t clock;\r\n        struct tm *tm;        \r\n        char tbuf[20];\r\n\r\n        FILE *res;\r\n        char buf[256];\r\n        res=popen(\"ping 192.168.0.249\", \"r\");\r\n\r\n        while (fgets(buf, sizeof(buf), res))\r\n        {\r\n                if (bcmp(buf, \"Reply\", 5) == 0 || bcmp(buf, \"Request\", 7) == 0)\r\n                {\r\n                        time(&clock);\r\n                        tm=localtime(&clock );\r\n                        strftime(tbuf, 20, \"%Y-%m-%d %H:%M:%S\", tm);\r\n                        printf(\"%s\\t%s\", tbuf, buf);\r\n                }\r\n        }\r\n        pclose(res);\r\n        return 0;\r\n}\r\n
复制代码

作者: slash001    时间: 2005-09-20 10:40
标题: 如何在ping 命令结果前面加上时间日期!!!
原帖由 \"b.s.d\" 发表:\n\r\n我的是2003
\r\n将Windows脚本宿主升级到5.6试试
作者: carrison    时间: 2005-09-20 12:29
标题: 如何在ping 命令结果前面加上时间日期!!!
[quote]原帖由 \"slash001\"][/quote 发表:\n\r\nunix下C编程也会,老弟全才啊, 就差Java的了 \r\n你让俺看到了中国软件的希望啊,哈哈
作者: slash001    时间: 2005-09-20 13:23
标题: 如何在ping 命令结果前面加上时间日期!!!
呵呵,我不是做开发的,就会简单的瞎写点,见笑了
作者: carrison    时间: 2005-09-20 13:50
标题: 如何在ping 命令结果前面加上时间日期!!!
呵呵,做管理的都会瞎写点就很难得了
作者: platinum    时间: 2005-09-20 15:25
标题: 如何在ping 命令结果前面加上时间日期!!!
如果是在 Linux 下面,可以这样\r\n
  1. \r\n# while :;do ping -c 1 172.17.39.251|awk \'/ttl=/\'|sed \"s/^/`date +%Y-%m-%d\\|%T` /\";sleep 1;done\r\n
复制代码
\r\n\r\n\r\n显示效果如下\r\n
\r\n[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\r\n2005-09-20|15:24:40 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.240 ms\r\n2005-09-20|15:24:41 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.235 ms\r\n2005-09-20|15:24:42 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.220 ms\r\n2005-09-20|15:24:43 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.224 ms\r\n2005-09-20|15:24:45 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.211 ms\r\n2005-09-20|15:24:46 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.211 ms\r\n2005-09-20|15:24:47 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.222 ms\r\n2005-09-20|15:24:48 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.221 ms\r\n2005-09-20|15:24:49 64 bytes from 172.17.39.251: icmp_seq=0 ttl=128 time=0.222 ms\r\n\r\n[root@PT_LINUX boot]#\r\n

作者: 无心。有心    时间: 2005-09-26 08:48
标题: 如何在ping 命令结果前面加上时间日期!!!
我想请问一下为什么在我的机子上这个命令不行呢
作者: Hex    时间: 2005-09-26 23:27
标题: 如何在ping 命令结果前面加上时间日期!!!
[quote]原帖由 \"slash001\"][/quote 发表:\n\r\n\r\ncool!
作者: ioiioi    时间: 2005-09-28 22:09
标题: 如何在ping 命令结果前面加上时间日期!!!
哪位高手可以将tping.vbs更改一下,可以自己设定ip和一些参数?\r\n比如cscript tping.vbs 192.168.1.1 -t -l 1000\r\n那就完美了。
作者: slash001    时间: 2005-09-30 10:01
标题: 如何在ping 命令结果前面加上时间日期!!!
  1. \r\nDim args, flag, unsuccOut\r\nargs=\"\"\r\notherout=\"\"\r\nflag=0\r\n\r\nIf WScript.Arguments.count = 0 Then\r\n        WScript.Echo \"Usage: cscript tping.vbs [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]\"\r\n        WScript.Echo \"                         [-s count] [[-j host-list] | [-k host-list]]\"\r\n        WScript.Echo \"                         [-r count] [-w timeout] destination-list\"\r\n        wscript.quit\r\nEnd if\r\n\r\nFor i=0 to WScript.Arguments.count - 1\r\n        args=args & \" \" & WScript.Arguments(i)\r\nNext\r\n\r\nSet shell = WScript.CreateObject(\"WScript.Shell\") \r\nSet re=New RegExp \r\nre.Pattern=\"^Reply|^Request\" \r\nSet myping=shell.Exec(\"ping\" & args)\r\n\r\nwhile Not myping.StdOut.AtEndOfStream \r\n   strLine=myping.StdOut.ReadLine() \r\n   r=re.Test(strLine) \r\n   If r Then \r\n        WScript.Echo date & \" \"& time & chr(9) & strLine\r\n        flag=1\r\n   Else\r\n        unsuccOut=unsuccOut & strLine\r\n   End if \r\nWend\r\n\r\nif flag = 0 then\r\n        WScript.Echo unsuccOut\r\nend if\r\n
复制代码
\r\n\r\nE:\\>;cscript tping.vbs 192.168.0.249 -t -l 1000\r\nMicrosoft (R) Windows Script Host Version 5.6\r\n版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。\r\n\r\n2005-9-30 10:03:29      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64\r\n2005-9-30 10:03:30      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64\r\n2005-9-30 10:03:31      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64\r\n2005-9-30 10:03:32      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64\r\n2005-9-30 10:03:33      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64\r\n2005-9-30 10:03:34      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64\r\n2005-9-30 10:03:35      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64\r\n2005-9-30 10:03:36      Reply from 192.168.0.249: bytes=1000 time<10ms TTL=64
作者: liutongzhu    时间: 2005-10-08 16:13
标题: 如何在ping 命令结果前面加上时间日期!!!
   \r\nzzzzzz
作者: xuesp001    时间: 2005-10-10 09:51
标题: 如何在ping 命令结果前面加上时间日期!!!
slash001的方法很不错罗!
作者: asd2004    时间: 2005-10-15 15:13
标题: 如何在ping 命令结果前面加上时间日期!!!
太COOL了, slash001  你就是我的偶像啊!!
作者: plumlee    时间: 2005-10-20 16:56
标题: 如何在ping 命令结果前面加上时间日期!!!
今天试了。可以引入到excel中做成曲线图~~
作者: excellent    时间: 2005-11-03 16:30
原帖由 AmoyOriole 于 2005-9-13 17:45 发表\r\n@echo off\r\n:START\r\ndate/t >;>; aa.txt\r\ntime/t >;>; aa.txt\r\nping 10.111.23.1 -n 10 >;>;aa.txt\r\ngoto START\r\n\r\n稍微变通的方法,呵呵。
\r\n\r\n\r\n问一下 \">;>; \" 是什么意思呢??
作者: rainballdh    时间: 2005-11-04 19:31
原帖由 archangle 于 2005-9-9 13:31 发表\r\n我有一个笨办法\r\nwhile [ 1 ];do\r\ndate;ping ip -c 1\r\ndone
\r\n这个怎么运行呀?
作者: rainballdh    时间: 2005-11-04 19:32
知道料,直接在终端运行
作者: zhxf_1    时间: 2005-11-09 15:13
楼上的,语法好象有点问题啊 !
作者: webcup    时间: 2005-11-09 20:50
CreateObject&#40\r\n\r\nMicrosoft (R) Windows Script Host Version 5.6\r\nCopyright (C) Microsoft Corporation 1996-2001. All rights reserved.\r\n\r\nC: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





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