天天看點

[FUNC]擷取DNS位址

轉自:GetDnsAddress

https://github.com/jNizM/AHK_Scripts/blob/master/src/net/GetDnsAddress.ahk

; ===============================================================================================================================
; Get a list of DNS servers used by the local computer.
; ===============================================================================================================================

GetDnsAddress()
{
    if (DllCall("iphlpapi.dll\GetNetworkParams", "ptr", 0, "uint*", size) = 111) && !(VarSetCapacity(buf, size, 0))
        throw Exception("Memory allocation failed for FIXED_INFO struct", -1)
    if (DllCall("iphlpapi.dll\GetNetworkParams", "ptr", &buf, "uint*", size) != 0)
        throw Exception("GetNetworkParams failed with error: " A_LastError, -1)
    addr := &buf, DNS_SERVERS := []
    DNS_SERVERS[1] := StrGet(addr + 264 + (A_PtrSize * 2), "cp0")
    ptr := NumGet(addr+0, 264 + A_PtrSize, "uptr")
    while (ptr) {
        DNS_SERVERS[A_Index + 1] := StrGet(ptr+0 + A_PtrSize, "cp0")
        ptr := NumGet(ptr+0, "uptr")
    }
    return DNS_SERVERS
}

; ===============================================================================================================================

for i, v in GetDnsAddress()
    MsgBox % v

ExitApp