欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-10 13:41:36
复制代码 代码如下:function getipaddress() dim flag, source set getipobj = wscript.ge...

复制代码 代码如下:

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