- 论坛徽章:
- 0
|
如何在ping 命令结果前面加上时间日期!!!
C不怎么用,随便写了一个,呵呵
Win2000 Cygwin下编译测试通过
- #include <stdio.h>;
- #include <string.h>;
- #include <time.h>;
- int main(int argc, char *argv[])
- {
- time_t clock;
- struct tm *tm;
- char tbuf[20];
- FILE *res;
- char buf[256];
- res=popen("ping 192.168.0.249", "r");
- while (fgets(buf, sizeof(buf), res))
- {
- if (bcmp(buf, "Reply", 5) == 0 || bcmp(buf, "Request", 7) == 0)
- {
- time(&clock);
- tm=localtime(&clock );
- strftime(tbuf, 20, "%Y-%m-%d %H:%M:%S", tm);
- printf("%s\t%s", tbuf, buf);
- }
- }
- pclose(res);
- return 0;
- }
复制代码 |
|