脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - VBS - VBS获取外网IP地址并发送到指定邮箱的代码

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

2020-08-10 11:09enun VBS

以前脚本之家发过类似功能的文章,这篇文章的获取网站不同,实现代码也不错,喜欢的朋友可以测试下

复制代码 代码如下:


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

延伸 · 阅读

精彩推荐