-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathGetDnsAddress.ahk
26 lines (22 loc) · 1.16 KB
/
GetDnsAddress.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
; ===============================================================================================================================
; 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