-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGetDnsServerList.ahk
48 lines (41 loc) · 1.65 KB
/
GetDnsServerList.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
; =============================================================================================================================================================
; Author ........: jNizM
; Released ......: 2021-04-22
; Modified ......: 2023-01-12
; Tested with....: AutoHotkey v2.0.2 (x64)
; Tested on .....: Windows 11 - 22H2 (x64)
; Function ......: GetDnsServerList()
;
; Parameter(s)...: No parameters used
;
; Return ........: Gets a list of DNS servers for the local computer.
; =============================================================================================================================================================
#Requires AutoHotkey v2.0
GetDnsServerList()
{
static ERROR_SUCCESS := 0
static ERROR_BUFFER_OVERFLOW := 111
if (DllCall("iphlpapi\GetNetworkParams", "Ptr", 0, "UInt*", &Size := 0, "UInt") = ERROR_BUFFER_OVERFLOW)
{
Buf := Buffer(Size)
if (DllCall("iphlpapi\GetNetworkParams", "Ptr", Buf, "UInt*", Size, "UInt") = ERROR_SUCCESS)
{
DNS_SERVERS := Array()
DNS_SERVERS.Push(StrGet(Buf.Ptr + 264 + (A_PtrSize * 2), "CP0"))
IPAddr := NumGet(Buf.Ptr + 264 + A_PtrSize, "UPtr")
while (IPAddr)
{
DNS_SERVERS.Push(StrGet(IPAddr + A_PtrSize, "CP0"))
IPAddr := NumGet(IPAddr, "UPtr")
}
return DNS_SERVERS
}
}
return
}
; =============================================================================================================================================================
; Example
; =============================================================================================================================================================
DNS := GetDnsServerList()
loop DNS.Length
MsgBox DNS[A_Index]