免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: jhgzzq

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

论坛徽章:
0
发表于 2005-09-19 07:37 |显示全部楼层

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

slash001 GG的脚本的确8错!   

论坛徽章:
0
发表于 2005-09-19 09:52 |显示全部楼层

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

还是vbs功能强大,呵呵,谁用perl来一个?

论坛徽章:
0
发表于 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
发表于 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'

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

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

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

论坛徽章:
0
发表于 2005-09-20 08:41 |显示全部楼层

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

[quote]原帖由 "slash001"][/quote 发表:


难不住你了,老弟再用C写一个?哈哈

论坛徽章:
0
发表于 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

论坛徽章:
2
丑牛
日期:2013-09-29 09:47:222015七夕节徽章
日期:2015-08-21 11:06:17
发表于 2005-09-20 09:22 |显示全部楼层

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

收藏,不错不错

论坛徽章:
0
发表于 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

论坛徽章:
0
发表于 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. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP