小玩意儿,参考了网上的例子,发到这里玩玩。
文件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