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

获取外网IP并发送到指定邮箱的vbs代码[已测]

程序员文章站 2022-04-10 08:19:57
复制代码 代码如下:''getip set http=createobject("microsoft.xmlhttp") ipp="http://www.ip138.com...
复制代码 代码如下:

''getip
set http=createobject("microsoft.xmlhttp")
ipp="http://www.ip138.com/ip2city.asp"
http.open "get",ipp,false
http.send
ss=bytes2bstr(http.responsebody)
intstra = instr(1,ss,"[",1)+1
sss=mid(ss,intstra)
intstrb = instr(1,sss,"]",1)-1
ss=mid(ss,intstra,intstrb)
'wscript.echo ss

function bytes2bstr(vin)
strreturn = ""
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytes2bstr = strreturn
end function

''sendemail
namespace = "http://schemas.microsoft.com/cdo/configuration/"
set email = createobject("cdo.message")
email.from = "发送邮箱"
email.to = "接收邮箱"
email.subject = "主题"
email.textbody = ss&date() 'ss为获取到的ip 
'email.addattachment "附件的路径例如:c:\foo.zip"
with email.configuration.fields
.item(namespace&"sendusing") = 2
.item(namespace&"smtpserver") = "smtp.163.com" 'smtp服务器地址
.item(namespace&"smtpserverport") = 25
.item(namespace&"smtpauthenticate") = 1
.item(namespace&"sendusername") = "账户名,发送邮箱的"
.item(namespace&"sendpassword") = "密码"
.update
end with
email.send

注意代码中的参数设置。