- arrIP = Array("192.168.0.1", "www.baidu.com", "74.125.71.14")
- Dim arrCnt() : Redim arrCnt(UBound(arrIP))
-
- WQL = "Select * from Win32_PingStatus Where Address='" _
- & Join(arrIP, "' OR Address='") & "'"
-
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set ts = fso.OpenTextFile("netstat.log", 8, true)
- Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
- Do
- i = 0
- Set colItems = objWMIService.ExecQuery(WQL, , 48)
- For Each objItem in colItems
- If objItem.StatusCode = 11010 Then
- arrCnt(i) = arrCnt(i) + 1
- if arrCnt(i)=3 then ts.WriteLine Now() & " " & objItem.Address & " 有丢包"
- if arrCnt(i)=10 then
- SendMail "MyAccount@163.com", "password", "SendTo@163.com", _
- "网络丢包", objItem.Address & " 丢包严重,请检查网络"
- end if
- Else
- arrCnt(i) = 0
- End If
- i = i + 1
- Next
- Loop
-
- 'SendMail "MyAccount@163.com", "password", "SendTo@163.com", "邮件主题", "邮件内容"
- Sub SendMail(Account, Password, SendTo, Subject, Body)
- 'http://www.cnblogs.com/cxy521/archive/2008/01/22/1048802.html
- On Error Resume Next
- const MsSpace = "http://schemas.microsoft.com/cdo/configuration/"
- dim CDO, Server
- Set CDO = CreateObject("CDO.Message")
- CDO.From = Account '发送邮件的帐号
- CDO.To = SendTo '主送邮件地址
- CDO.Subject = Subject '邮件主题
- CDO.Textbody = Body '邮件内容
- Server = Split(Account, "@", -1, vbTextCompare)
- With CDO.Configuration.Fields
- .Item(MsSpace&"sendusing") = 2 '发信端口
- .Item(MsSpace&"smtpserver") = "smtp." & Server(1) 'SMTP服务器地址
- .Item(MsSpace&"smtpserverport") = 25 'SMTP服务器端口
- .Item(MsSpace&"smtpauthenticate") = 1 'Basic验证方式
- .Item(MsSpace&"sendusername") = Server(0) '邮件帐号
- .Item(MsSpace&"sendpassword") = Password '邮件密码
- .Update
- End With
- CDO.Send()
- End Sub
复制代码
|