- 论坛徽章:
- 0
|
如何在ping 命令结果前面加上时间日期!!!
C不怎么用,随便写了一个,呵呵\r\nWin2000 Cygwin下编译测试通过\r\n- \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
复制代码 |
|