VBS检查服务器ping值
作者:刚子 日期:2010-04-28
运行下面的脚本可以返回相应IP的ping值:
程序代码
利用此功能我们还可以延伸为一个简单的监控功能,比如说我的:
简单解释下我的脚本,每隔1分钟ping一下指定IP,如果发现可以正常返回times值,则自动播放指定的音乐文件,同时给我指定的邮箱发送邮件。整个过程是一个死循环,也就是说在你没有结束掉这个脚本之前他会不断的发出警告。我写此脚本的原因是昨晚服务器重装系统,因为不知道老外什么时候装完,所以把这个脚本挂在了本机上,没关机去睡觉,凌晨6点左右电脑突然播放音乐。于是乎起床检查,果然服务器装好了,呵呵。利用此脚本可以延伸很多其他功能,比如说监控服务器返回的times值来做不同的事情或者警告等等。如果觉得发邮件那个部分没用,可以删除之。
程序代码
程序代码On Error Resume Next
ip = "8.8.8.8"
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & ip & "'")
For Each objStatus in objPing
msgbox objStatus.ResponseTime
Next
ip = "8.8.8.8"
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & ip & "'")
For Each objStatus in objPing
msgbox objStatus.ResponseTime
Next
利用此功能我们还可以延伸为一个简单的监控功能,比如说我的:
简单解释下我的脚本,每隔1分钟ping一下指定IP,如果发现可以正常返回times值,则自动播放指定的音乐文件,同时给我指定的邮箱发送邮件。整个过程是一个死循环,也就是说在你没有结束掉这个脚本之前他会不断的发出警告。我写此脚本的原因是昨晚服务器重装系统,因为不知道老外什么时候装完,所以把这个脚本挂在了本机上,没关机去睡觉,凌晨6点左右电脑突然播放音乐。于是乎起床检查,果然服务器装好了,呵呵。利用此脚本可以延伸很多其他功能,比如说监控服务器返回的times值来做不同的事情或者警告等等。如果觉得发邮件那个部分没用,可以删除之。
程序代码On Error Resume Next
Do
ip = "8.8.8.8"
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & ip & "'")
For Each objStatus in objPing
if objStatus.ResponseTime>1 then
Set WshShell = WScript.CreateObject("WScript.Shell")
strSoundFile = "C:\Windows\Media\ringin.wav"
strCommand = "sndrec32 /play /close " & Chr(34) & strSoundFile & Chr(34)
WshShell.Run strCommand, 0, True
NameSpace = "http://schemas.microsoft.com/cdo/configuration/"
Set Email = CreateObject("CDO.Message")
Email.From = "发件人@126.com"
Email.To = "收件人@139.com"
Email.Subject = "国外服务器可以可以PING通了。"
Email.Textbody = "国外服务器可以可以PING通了。"
With Email.Configuration.Fields
.Item(NameSpace&"sendusing") = 2
.Item(NameSpace&"smtpserver") = "smtp.126.com"
.Item(NameSpace&"smtpserverport") = 25
.Item(NameSpace&"smtpauthenticate") = 1
.Item(NameSpace&"sendusername") = "账号"
.Item(NameSpace&"sendpassword") = "密码"
.Update
End With
Email.Send
end if
Next
Wscript.Sleep 60000
Loop
Do
ip = "8.8.8.8"
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & ip & "'")
For Each objStatus in objPing
if objStatus.ResponseTime>1 then
Set WshShell = WScript.CreateObject("WScript.Shell")
strSoundFile = "C:\Windows\Media\ringin.wav"
strCommand = "sndrec32 /play /close " & Chr(34) & strSoundFile & Chr(34)
WshShell.Run strCommand, 0, True
NameSpace = "http://schemas.microsoft.com/cdo/configuration/"
Set Email = CreateObject("CDO.Message")
Email.From = "发件人@126.com"
Email.To = "收件人@139.com"
Email.Subject = "国外服务器可以可以PING通了。"
Email.Textbody = "国外服务器可以可以PING通了。"
With Email.Configuration.Fields
.Item(NameSpace&"sendusing") = 2
.Item(NameSpace&"smtpserver") = "smtp.126.com"
.Item(NameSpace&"smtpserverport") = 25
.Item(NameSpace&"smtpauthenticate") = 1
.Item(NameSpace&"sendusername") = "账号"
.Item(NameSpace&"sendpassword") = "密码"
.Update
End With
Email.Send
end if
Next
Wscript.Sleep 60000
Loop
评论: 0 | 引用: 0 | 查看次数: -
发表评论
上一篇
下一篇

文章来自:
Tags: