免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: jhgzzq
打印 上一主题 下一主题

如何在ping 命令结果前面加上时间日期!!! [复制链接]

论坛徽章:
0
1 [报告]
发表于 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

论坛徽章:
0
2 [报告]
发表于 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 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2005-09-19 18:20 |显示全部楼层

如何在ping 命令结果前面加上时间日期!!!

我是在Win2000下测试的
Microsoft (R) Windows Script Host Version 5.6

论坛徽章:
0
4 [报告]
发表于 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. }
复制代码

论坛徽章:
0
5 [报告]
发表于 2005-09-20 10:40 |显示全部楼层

如何在ping 命令结果前面加上时间日期!!!

原帖由 "b.s.d" 发表:

我的是2003

将Windows脚本宿主升级到5.6试试

论坛徽章:
0
6 [报告]
发表于 2005-09-20 13:23 |显示全部楼层

如何在ping 命令结果前面加上时间日期!!!

呵呵,我不是做开发的,就会简单的瞎写点,见笑了

论坛徽章:
0
7 [报告]
发表于 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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP