Tools:实现ping操作带时间戳【windows+linux】

【windows下】:

ping.vbs

Dim args, flag, unsuccOut
args=""
otherout=""
flag=0

If WScript.Arguments.count = 0 Then
WScript.Echo "Usage: cscript tping.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()
‘WScript.Echo  "原数据" & chr(9) & strLine
   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

ping.bat

cscript ping.vbs 10.8.115.127 -n 10 >ping_log.txt

执行ping.bat即可

效果如下:

Microsoft (R) Windows Script Host Version 5.812
版权所有(C) Microsoft Corporation。保留所有权利。

2018/11/19 14:17:13 来自 10.8.115.115 的回复: 字节=32 时间<1ms TTL=200
2018/11/19 14:17:14 来自 10.8.115.115 的回复: 字节=32 时间<1ms TTL=200
2018/11/19 14:17:15 来自 10.8.115.115 的回复: 字节=32 时间<1ms TTL=200
2018/11/19 14:17:16 来自 10.8.115.115 的回复: 字节=32 时间=1ms TTL=200

【linux下】

ping $1 |while read line;do echo `date`$line;done >> ping_test.log

效果:

[email protected]/root/chen#ping 10.8.210.101 |while read line;do echo `date`$line;done
Mon Nov 19 14:23:42 CST 2018PING 10.8.210.101 (10.8.210.101) 56(84) bytes of data.
Mon Nov 19 14:23:42 CST 201864 bytes from 10.8.210.101: icmp_seq=1 ttl=64 time=0.257 ms
Mon Nov 19 14:23:43 CST 201864 bytes from 10.8.210.101: icmp_seq=2 ttl=64 time=0.163 ms
Mon Nov 19 14:23:44 CST 201864 bytes from 10.8.210.101: icmp_seq=3 ttl=64 time=0.141 ms
Mon Nov 19 14:23:45 CST 201864 bytes from 10.8.210.101: icmp_seq=4 ttl=64 time=0.160 ms
Mon Nov 19 14:23:46 CST 201864 bytes from 10.8.210.101: icmp_seq=5 ttl=64 time=0.148 ms

原文地址:https://www.cnblogs.com/channy14/p/9982926.html

时间: 2024-08-30 17:43:48

Tools:实现ping操作带时间戳【windows+linux】的相关文章

ping IP 带时间戳循环显示并写入日志

在工作中,判断网络是否通畅,首选命令就是ping,但有时候我们需要持续ping一个或多个地址时,需要加 -t 即可,但有时候需要在ping的时候加入时间戳并把ping记录写入到日志里面,方法如下: windos版: 首选把下面代码复制到文本里去,然后把扩展名更改为.bat @echo off @echo.---------------------------------------------------------- @echo. 一 Author: aゞ锦衣卫 @echo. 键 Remind

Matlab命令——目录操作(windows&amp;Linux)

Matlab命令——目录操作(windows&Linux) 1. filesep用于返回当前平台的目录分隔符,Windows是反斜杠(\),Linux是斜杠(/).有时此命令结合ispc命令使用,可以灵活的设置目录分割符. 2. fullfile用于将若干字符串连接成一个完整的路径,根据不同的操作系统自动填充目录分割符.例如:>> f=fullfile('D:','Matlab','example.txt')f=D:\Matlab\example.txt(在Windows中,“D:\”

一篇文章带你入门Linux——马哥Linux基础学习笔记

1.课程体系: 中级: 初级:系统基础 中级:系统管理.服务安全及服务管理.Shell脚本: 高级: MySQL数据库: cache & storage 集群: Cluster lb: 4layer 7layer ha: 分布式: zookeeper 分布式文件系统 虚拟化技术: xen kvm Openstack:IAAS云: 运维工具: ansible puppet(ruby), saltstack(python) 监控工具: zabbix 大数据处理: hadoop spark, stor

Mentor.Graphics.Questa.VIP.v10.6.Windows.&amp;.Linux 2CD

ANSOFT产品: Ansys Electromagnetics Suite v16.0 Win64 1DVD + 3CD inclueded: - Ansys Electronics Desktop 2015.0.0 (HFSS, HFSS 3D Layout, HFSS-IE, 2D Extractor, Q3D Extractor) - Ansys Electromagnetics 16.0 Modeler Files for CATIAV5 - Ansys Electromagnetic

Windows Azure+Windows+Linux多环境下Tomcat服务的安装及配置集合

Windows Azure+Windows+Linux多环境下的Tomcat服务的安装及配置集合 说到Tomcat服务,相信大家都很熟悉了,当然也这包括安装及配置:我们都知道Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选.对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应HTML(标准通用标记语言下的一个应用)页面的访问请求.实际上To

Windows+Linux安装Python工具setuptools

Windows+Linux安装Python工具setuptools setuptools是 Python Enterprise Application Kit(PEAK)的一个副项目,它 是一组Python的 distutilsde工具的增强工具(适用于 Python 2.3.5 以上的版本,64 位平台则适用于 Python 2.4 以上的版本),可以让程序员更方便的创建和发布 Python 包,特别是那些对其它包具有依赖性的状况. 经常接触Python可能会注意到,当需要安装第三方pytho

Telnet部署与启动 windows&&linux

Telnet部署与启动 windows&&linux 一.win7下默认是禁用telnet服务的(按顺序执行即可) 重新启动Telnet方法如下: 1.如果你直接到控制面板的管理工具里的服务项里去找telnet的话,那是徒劳无功 的,因为默认根本就没有这一服务.当然,你可以通过如下方式搞定."控制面 板" 一〉"程序" 一〉"打开或关闭windows功能",在里面你可以看到许多服务项,选 择"telnet服务器"

Windows + linux 双系统修改启动顺序

使用Windows + linux 双系统的用户可以使用如下方法修改启动顺序 我用的是Fedora 一.简单命令操作 1. 首先找到Windows的菜单menuentry. # cat /boot/grub2/grub.cfg | grep Windows 输出: menuentry 'Windows 7 (loader) (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-58D8931

IDA Pro Disassembler 6.8.15.413 (Windows, Linux, Mac)

IDA: What's new in 6.8 Highlights This is mainly a maintenance release, so our focus was on fixing bugs. However, there are some improvements too: Support for long names. In previous versions of IDA names were limited to 511 bytes. This was causing p