VBS调用ping检测ip连通情况

小玩意儿,参考了网上的例子,发到这里玩玩。

文件1:Pingtest.vbs

option explicit

Function MyPing (oHost)
Dim oPing,oRetStatus
Set oPing=GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
          ("select * from Win32_PingStatus where address ='" & oHost & "'")
For Each oRetStatus In oPing
     If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode<>0 Then
        MyPing="Pinging " & ohost & ", Request Timeout with StatusCode " & oRetStatus.StatusCode
     Else
        MyPing="Pinging " & ohost & " with " & oRetStatus.BufferSize & " bytes of data:" & vbCrLf
        MyPing=MyPing & "Coming from " & oRetStatus.ProtocolAddress & " Replies: "
        MyPing=MyPing & "Bytes=" & oRetStatus.BufferSize & " "
        MyPing=MyPing & "Time=" & oRetStatus.ResponseTime & "(ms) "
        MyPing=MyPing & "TTL=" & oRetStatus.ResponseTimeToLive & "(s) "
     End If
Next
End Function
 
Dim fso,fread,str,strarry,ipstr  
Set fso=createobject("scripting.filesystemobject")  
Set fread=fso.opentextfile("iplist.txt",1)  
str=fread.readall  
fread.close  
if str="" then  
    wscript.echo "file is empty!"  
    wscript.quit  
end if  
strarry=split(str,vbcrlf)  
for each ipstr in strarry  
    wscript.echo MyPing(ipstr)
next  
set fso=nothing


'WScript.Echo MyPing2("192.168.1.250")


文件2:iplist.txt,用来放你想检测的ip地址。

Example

192.168.1.100

192.168.2.200

220.181.112.244

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值