其他分享
首页 > 其他分享> > 使用VBS脚本实现Ali_DDNS

使用VBS脚本实现Ali_DDNS

作者:互联网

使用VBS脚本实现Ali_DDNS

有以字节方式读取文本
有以字节方式覆写文本
有对两个字节数组进行HMAC-SHA1运算
有利用CMD进行SHA1计算
有对字节数组BASE64编码
python SDK我安装不上,就想写个VBS版的。

Const SHA1_size_B = 20 '20 Byte
Const HMAC_B = 64 
Const ipv4_type = "([0-9]{1,3}\.){3}[0-9]{1,3}"
Const ipv6_type = "((([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4})|(([0-9a-fA-F]{1,4}:){6}(:[0-9a-fA-F]{1,4}){1,1})|(([0-9a-fA-F]{1,4}:){5}(:[0-9a-fA-F]{1,4}){1,2})|(([0-9a-fA-F]{1,4}:){4}(:[0-9a-fA-F]{1,4}){1,3})|(([0-9a-fA-F]{1,4}:){3}(:[0-9a-fA-F]{1,4}){1,4})|(([0-9a-fA-F]{1,4}:){2}(:[0-9a-fA-F]{1,4}){1,5})|(([0-9a-fA-F]{1,4}:){1}(:[0-9a-fA-F]{1,4}){1,6})|(([0-9a-fA-F]{1,4}:){1,6}:)|(:(:[0-9a-fA-F]{1,4}){1,6})|(::))"

Function UniconToB(ustr)
    Dim newbyte , i
    Redim newbyte(Len(ustr) - 1)
    For i = 1 To Len(ustr)
        newbyte(i - 1) = asc(Mid(ustr, i, 1)) and &H00FF
    Next'i
    UniconToB = newbyte
End Function'unicon字符串转字节数组

Function HMAC_SHA1(HMAC_msg, HMAC_key)
    If VarType(HMAC_msg)=8 Then
        HMAC_msg=UniconToB(HMAC_msg)
    End If
    If VarType(HMAC_key)=8 Then
        HMAC_key=UniconToB(HMAC_key)
    End If
    Real_Key = get_realkey(HMAC_key)
    Real_Msg = HMAC_msg
    HMAC_SHA1 = SHA1_Encrypt(Bin_add(Bin_xor(Real_Key, &H5C), SHA1_Encrypt(Bin_add(Bin_xor(Real_Key, &H36), Real_Msg))))
End Function' HMAC_SHA1
Function Base64Encode(Str)
    Const B64_CHAR_DICT = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
    mods = (UBound(Str) + 1) Mod 3'除以3的余数
    length = UBound(Str) + 1 - mods
    If mods <> 0 Then 
        b2 = 4
    Else 
        b2 = 0
    End If
    Redim buf(length / 3 * 4 + b2 - 1)
    Dim i
    For i = 0 To length - 1 Step 3
        buf(i / 3 * 4) = (Str(i) And &HFC) / &H4
        buf(i / 3 * 4 + 1) = (Str(i) And &H3) * &H10 + (Str(i + 1) And &HF0) / &H10
        buf(i / 3 * 4 + 2) = (Str(i + 1) And &HF) * &H4 + (Str(i + 2) And &HC0) / &H40
        buf(i / 3 * 4 + 3) = Str(i + 2) And &H3F
    Next
    If mods = 1 Then 
        buf(length / 3 * 4) = (Str(length) And &HFC) / &H4
        buf(length / 3 * 4 + 1) = (Str(length) And &H3) * &H10
        buf(length / 3 * 4 + 2) = 64
        buf(length / 3 * 4 + 3) = 64
    ElseIf mods = 2 Then
        buf(length / 3 * 4) = (Str(length) And &HFC) / &H4
        buf(length / 3 * 4 + 1) = (Str(length) And &H3) * &H10 + (Str(length + 1) And &HF0) / &H10
        buf(length / 3 * 4 + 2) = (Str(length + 1) And &HF) * &H4
        buf(length / 3 * 4 + 3) = 64
    End If
    For i = 0 To UBound(buf)
        Base64Encode = Base64Encode & Mid(B64_CHAR_DICT, buf(i) + 1, 1)
    Next
End Function
Function SHA1_Encrypt(Buf)
    Dim Path,Path2
    Path = "D:\1.txt"
    Path2 = "D:\2.txt"
    Call WriteBinary(Path, Buf)
    Call cmdout("CertUtil -hashfile " & Path & " SHA1", Path2)
    SHA1_result = RegexFind("[0-9a-zA-Z]{40}",ReadFile(Path2))
    Dim aBuf()
    If len(SHA1_result)=SHA1_size_B * 2 Then
        Redim aBuf(SHA1_size_B - 1)
        For hex_i = 0 To SHA1_size_B - 1
            aBuf(hex_i) = Hex2Dec(Mid(SHA1_result, hex_i * 2 + 1, 2))
        Next'hex_i
    End If
    SHA1_Encrypt = aBuf
End Function'对字节数组进行SHA1运算

其他详细的内容可以在我上传的资源找到。
Ali_DDNS_vbs.vbs

VBS脚本唯一的好处就是运行时要求不高。

标签:SHA1,Ali,9a,VBS,fA,length,DDNS,Str,buf
来源: https://blog.csdn.net/fzipw/article/details/113705737