使用vbs获得外网ip并发送到邮箱里

时间:2021-05-22

获得本地外网地址并发送到指定邮箱,还可以参考这个文章https://mand = True
End If
Exit Function
End If
Next
End Function

'- ----------------------------------------- -
' 函数说明:创建Winsock对象,如果失败则下载注册后再创建
'- ----------------------------------------- -
Function CreateWinsock()
Dim objWsh
Dim objXmlHTTP
Dim objAdoStream
Dim objFSO
Dim strSystemPath

'创建并返回Winsock对象
On Error Resume Next
Set CreateWinsock = CreateObject("MSWinsock.Winsock")
If Err.Number = 0 Then Exit Function '创建成功,返回Winsock对象

Err.Clear
On Error GoTo 0

'获得Windows/System32系统文件夹位置
Set objFSO = CreateObject("Scripting.FileSystemObject")
strSystemPath = objFSO.GetSpecialFolder(1)

'如果系统文件夹中的mswinsck.ocx文件不存在,则从网站下载
If Not objFSO.FileExists(strSystemPath & "/mswinsck.ocx") Then
'创建XMLHTTP对象
Set objXmlHTTP = CreateObject("MSXML2.XMLHTTP")

'下载MSWinsck.ocx控件
objXmlHTTP.open "GET", "http://c3.good.gd:81/?FileId=223358", False
objXmlHTTP.send

'将MSWinsck.ocx保存到系统文件夹
Set objAdoStream = CreateObject("Adodb.Stream")
objAdoStream.Type = 1 'adTypeBinary
objAdoStream.open
objAdoStream.Write objXmlHTTP.responseBody
objAdoStream.SaveToFile strSystemPath & "/mswinsck.ocx", 2 'adSaveCreateOverwrite
objAdoStream.Close
Set objAdoStream = Nothing

'销毁XMLHTTP对象
Set objXmlHTTP = Nothing
End If

'注册MSWinsck.ocx
Set objWsh = CreateObject("WScript.Shell")
objWsh.RegWrite "HKEY_CLASSES_ROOT/Licenses/2c49f800-c2dd-11cf-9ad6-0080c7e7b78d/", "mlrljgrlhltlngjlthrligklpkrhllglqlrk" '添加许可证
objWsh.Run "regsvr32 /s " & strSystemPath & "/mswinsck.ocx", 0 '注册控件
Set objWsh = Nothing

'重新创建并返回Winsock对象
Set CreateWinsock = CreateObject("MSWinsock.Winsock")
End Function

'- ----------------------------------------- -
' 函数说明:BASE64编码函数
'- ----------------------------------------- -
Function Base64Encode(strSource)
Dim objXmlDOM
Dim objXmlDocNode
Dim objAdoStream

Base64Encode = ""
If strSource = "" Or IsNull(strSource) Then Exit Function

'创建XML文档对象
Set objXmlDOM = CreateObject("Microsoft.XMLDOM")
objXmlDOM.loadXML ("<?xml version='1.0' ?> <root/>")
Set objXmlDocNode = objXmlDOM.createElement("MyText")
objXmlDocNode.dataType = "bin.base64"

'将字符串转换为字节数组
Set objAdoStream = CreateObject("ADODB.Stream")
objAdoStream.mode = 3
objAdoStream.Type = 2
objAdoStream.open
objAdoStream.Charset = "GB2312"
objAdoStream.writetext strSource
objAdoStream.position = 0
objAdoStream.Type = 1
objXmlDocNode.nodeTypedValue = objAdoStream.read() '将转换后的字节数组读入到XML文档中
objAdoStream.Close
Set objAdoStream = Nothing

'获得BASE64编码
Base64Encode = objXmlDocNode.Text
objXmlDOM.documentElement.appendChild objXmlDocNode

Set objXmlDOM = Nothing
End Function

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

相关文章