博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何使PING命令带上日期,做长久的跟踪
阅读量:7114 次
发布时间:2019-06-28

本文共 1695 字,大约阅读时间需要 5 分钟。

LINUX:

while :;do ping -c 1 172.16.128.36|awk '/ttl=/'|sed "s/^/`date +%Y-%m-%d\|%T` /";sleep 1;done

执行结果

2011-03-08|15:55:49 64 bytes from 172.16.128.6: icmp_seq=0 ttl=252 time=0 ms

2011-03-08|15:55:50 64 bytes from 172.16.128.6: icmp_seq=0 ttl=252 time=0 ms
2011-03-08|15:55:51 64 bytes from 172.16.128.6: icmp_seq=0 ttl=252 time=0 ms
2011-03-08|15:55:52 64 bytes from 172.16.128.6: icmp_seq=0 ttl=252 time=0 ms

 

WINDOWS:

''

''使用方法
'';cscript ping.vbs 192.168.1.1 -t -l 1000
''
Dim args, flag, unsuccOut
args=""
otherout=""
flag=0

If WScript.Arguments.count = 0 Then

 WScript.Echo "Usage: cscript ping.vbs  [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]"
 WScript.Echo "                         [-s count] [[-j host-list] | [-k host-list]]"
 WScript.Echo "                         [-r count] [-w timeout] destination-list"
 wscript.quit
End if

For i=0 to WScript.Arguments.count - 1

 args=args & " " & WScript.Arguments(i)
Next

Set shell = WScript.CreateObject("WScript.Shell") 

Set re=New RegExp 
re.Pattern="^Reply|^Request" 
Set myping=shell.Exec("ping" & args)

while Not myping.StdOut.AtEndOfStream 

   strLine=myping.StdOut.ReadLine() 
   r=re.Test(strLine) 
   If r Then 
 WScript.Echo date & " "& time & chr(9) & strLine
 flag=1
   Else
 unsuccOut=unsuccOut & strLine
   End if 
Wend

if flag = 0 then

 WScript.Echo unsuccOut
end If

 保存成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
 

如果要长久保存,那么重定向到文件即可>

本文转自zylhsy 51CTO博客,原文链接:http://blog.51cto.com/yunlongzheng/509800,如需转载请自行联系原作者

你可能感兴趣的文章
android自定义view
查看>>
SQL日志文件的作用
查看>>
SQL注入原理 手工注入access数据库
查看>>
算24 (递归)
查看>>
方便查看 linux/include/asm/system.h
查看>>
sql中的!=判断的注意事项
查看>>
作业3(吴雪蕾)
查看>>
Stack Overflow大揭密:哪一种程序员工资最高?
查看>>
C# 链表 --增 -删-反转-删除最小值
查看>>
爬取全部的校园新闻
查看>>
JavaScriptCore
查看>>
union
查看>>
banner 跟随鼠标呈现视差效果
查看>>
linux给用户添加sudo权限
查看>>
前端基础(6)easyUI
查看>>
我有我的方向
查看>>
HBase常用Shell命令
查看>>
vim的个性化配置- 再谈vim的折叠和展开 -- 彻底掌握vim 的展开和折叠!
查看>>
Pytorch-nn.Module-modules()
查看>>
Linux 常用命令
查看>>