日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

一个在Windows下的ping脚本(使用WMI 的Win32_PingStatus 实现)

發布時間:2024/9/5 windows 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一个在Windows下的ping脚本(使用WMI 的Win32_PingStatus 实现) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? 非常不喜歡windows自帶Ping工具,慢吞吞不說結果也很不精確,非常不適合用來排查網絡故障,尤其是
對我這種急性子的人來說,更不能接受(有時候是比較急啦),于是就偷懶寫了以下這個東西,希望對大家有用:


set?objArgs?=?wscript.Arguments?


Dim?PacketReceived?,?PacketLost?,?MinimumTime?,?MaximumTime?,?AverageTime?,TimeSum?,?tmp

PacketReceived?
=?0
PacketLost?????
=?0
MinimumTime????
=?2000
MaximumTime????
=?0?
AverageTime????
=?0
TimeSum????????
=?0

WScript.Echo?
""
WScript.Echo?
"Pinging?"&objArgs(0)&"?with?32?bytes?of?data:"
WScript.Echo?
""


For?i?=?0?To?objArgs(1)-1

????
Set?objWMIService?=?GetObject("winmgmts:\\.\root\cimv2")
????
Set?colItems?=?objWMIService.ExecQuery?_
????????(
"Select?*?from?Win32_PingStatus?"?&?"Where?Address?=?'"?&?objArgs(0)?&?"'")
????
For?Each?objItem?in?colItems
????
????????
If?objItem.StatusCode?=?0?Then?
????????????
????????????TimeSum?
=?TimeSum?+?objItem.ResponseTime
????????????PacketReceived?
=?PacketReceived?+?1
????????????WScript.Echo?
"Reply?from?"&objArgs(0)&":?bytes="&objItem.ReplySize&"?time="&objItem.ResponseTime&"ms?TTL="&objItem.ResponseTimeToLive

????????????
If?objItem.ResponseTime?>?MaximumTime?Then?
????????????????MaximumTime?
=?objItem.ResponseTime
????????????
End?If?
????????
????????????
If?objItem.ResponseTime?<?MinimumTime?Then?
????????????????MinimumTime?
=?objItem.ResponseTime
????????????
End?If?
????????????
????????????????
????????
Else?
????????????
????????????WScript.Echo?
"Request?timed?out."
????????????PacketLost?
=?PacketLost?+?1
????????????????
????????
End?If??
????????
????
Next?
Next?


WScript.Echo?
""


If??PacketReceived?=?0??Then?

????WScript.Echo?
"Ping?statistics?for?"&objArgs(0)&":"
????WScript.Echo?????
"Packets:?Sent?=?"&objArgs(1)&",?Received?=?0,?Lost?=?"&objArgs(1)&"?(100%?loss),"


Else?

????tmp?
=?Round(PacketLost/objArgs(1),3)*100
????
????
If?Left(tmp?,?1)?=?"."?Then?
????????tmp?
=?"0"&tmp
????
End?If?
????
????WScript.Echo?
"Ping?statistics?for?"&objArgs(0)&":"
????WScript.Echo????
"Packets:?Sent?=?"&objArgs(1)&",?Received?=?"&PacketReceived&",?Lost?=?"&PacketLost&"?("&tmp&"%?loss),"
????WScript.Echo?
"Approximate?round?trip?times?in?milli-seconds:"
????WScript.Echo????
"Minimum?=?"&MinimumTime&"ms,?Maximum?=?"&MaximumTime&"ms,?Average?=?"&Round(TimeSum/(PacketReceived),0)&"ms"


End?If?








?寫得很粗糙,目前只支持2個參數,目的IP及Ping包數。等以后發大財了再完善一下,還有PowerShell 及Bash版本等...
????
?運行方法很簡單,把以上代碼保存為.vbs文件,通過命令行運行cscript *.vbs 即可,下面例子可供參考:


E:\VBS\TS>cscript arg.vbs 192.168.1.1 2
Microsoft (R) Windows Script Host Version 5.7
版權所有(C) Microsoft Corporation 1996-2001。保留所有權利。


Pinging 192.168.1.1 with 32 bytes of data:

Reply from 192.168.1.1: bytes=32 time=132ms TTL=64
Reply from 192.168.1.1: bytes=32 time=44ms TTL=64

Ping statistics for 192.168.1.1:
Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 44ms, Maximum = 132ms, Average = 88ms

E:\VBS\TS>cscript arg.vbs 192.168.1.2 2
Microsoft (R) Windows Script Host Version 5.7
版權所有(C) Microsoft Corporation 1996-2001。保留所有權利。


Pinging 192.168.1.2 with 32 bytes of data:

Request timed out.
Request timed out.

Ping statistics for 192.168.1.2:
Packets: Sent = 2, Received = 0, Lost = 2 (100% loss),

E:\VBS\TS>



轉載于:https://www.cnblogs.com/mrwsr/articles/1238518.html

總結

以上是生活随笔為你收集整理的一个在Windows下的ping脚本(使用WMI 的Win32_PingStatus 实现)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。