VBS获取外网IP地址并发送到指定邮箱的代码

时间:2021-05-22

复制代码 代码如下:
Function GetIPAddress()
Dim Flag, Source
Set GetIPObj = WScript.GetObject("http://ipseeker.cn//")
Flag = 0
For i=1 To 10
If GetIPObj.readyState = "complete" Then
Flag=1
Exit For
End If
WScript.Sleep 500
Next

If Flag = 0 Then
GetIPAddress = "Get IP Address Time Out ..."
Else
Source = GetIPObj.documentElement.innerText
Set Rep = New RegExp
Rep.Pattern="(\d+)\.(\d+)\.(\d+)\.(\d+)"
For Each result in Rep.Execute(Source)
GetIPAddress = result
Exit For
Next
End If
End Function

Function MailTo(MailAddress)
Dim NameSpace, MailObject

NameSpace = "http://schemas.microsoft.com/cdo/configuration/"

Set MailObject = CreateObject("CDO.Message")
MailObject.From = "*****@21cn.com"
MailObject.To = MailAddress
MailObject.Subject = "IP Address Information"

MailObject.Textbody = Now & ": " & GetIPAddress()

MailObject.Configuration.Fields.Item(NameSpace & "sendusing") = 2
MailObject.Configuration.Fields.Item(NameSpace & "smtpserver") = "smtp.21cn.com"
MailObject.Configuration.Fields.Item(NameSpace & "smtpserverport") = 25
MailObject.Configuration.Fields.Item(NameSpace & "smtpauthenticate") = 1
MailObject.Configuration.Fields.Item(NameSpace & "sendusername") = "*****"
MailObject.Configuration.Fields.Item(NameSpace & "sendpassword") = "*****"

MailObject.Configuration.Fields.Update
MailObject.Send
End Function

MailTo ("******@qq.com")


原文:http://www.enun.net/?p=1199

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章