Тема: AHK: Автоматизация роутеров через WinHttpRequest
TP-LINK.
login := "login"
pass := "pass"
link := "http://192.168.0.1"
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", link)
WebRequest.Send()
link .= "/userRpm/LoginRpm.htm?Save=Save"
Authorization := "Authorization=Basic " b64Encode(login ":" MD5(pass))
WebRequest.Open("GET", link)
WebRequest.SetRequestHeader("Cookie", Authorization)
WebRequest.Send()
msgbox % WebRequest.ResponseText ; получаем ссылку для дальнейших действий, помимо Cookie нужно будет отправлять referer
b64Encode(string)
{
VarSetCapacity(bin, StrPut(string, "UTF-8")) && len := StrPut(string, &bin, "UTF-8") - 1
if !(DllCall("crypt32\CryptBinaryToString", "ptr", &bin, "uint", len, "uint", 0x1, "ptr", 0, "uint*", size))
throw Exception("CryptBinaryToString failed", -1)
VarSetCapacity(buf, size << 1, 0)
if !(DllCall("crypt32\CryptBinaryToString", "ptr", &bin, "uint", len, "uint", 0x1, "ptr", &buf, "uint*", size))
throw Exception("CryptBinaryToString failed", -1)
return StrGet(&buf)
}
MD5(string, case := False) ; by SKAN | rewritten by jNizM
{
static MD5_DIGEST_LENGTH := 16
hModule := DllCall("LoadLibrary", "Str", "advapi32.dll", "Ptr")
, VarSetCapacity(MD5_CTX, 104, 0), DllCall("advapi32\MD5Init", "Ptr", &MD5_CTX)
, DllCall("advapi32\MD5Update", "Ptr", &MD5_CTX, "AStr", string, "UInt", StrLen(string))
, DllCall("advapi32\MD5Final", "Ptr", &MD5_CTX)
loop % MD5_DIGEST_LENGTH
o .= Format("{:02" (case ? "X" : "x") "}", NumGet(MD5_CTX, 87 + A_Index, "UChar"))
return o, DllCall("FreeLibrary", "Ptr", hModule)
}