当前位置: 移动技术网 > IT编程>脚本编程>VBScript > 获取外网IP并发送到指定邮箱的vbs代码[已测]

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

2017年12月08日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

''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

注意代码中的参数设置。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网