This repository has been archived by the owner on Nov 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathShowNetworkNames.ahk
45 lines (40 loc) · 2.25 KB
/
ShowNetworkNames.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
#NoEnv
VarSetCapacity(adapterGuid, 16), VarSetCapacity(adapterGuidStr, 140), adapters := GetAdaptersAddresses()
; Thanks to Lexikos and HotKeyIt for correcting my attempts
for INetwork in ComObjCreate("{DCB00C01-570F-4A9B-8D69-199FDBA5723B}").GetNetworks(1) { ; NLM_ENUM_NETWORK_CONNECTED ; NLM_ENUM_NETWORK_ALL := 3
; INetwork.SetCategory(1) ; NLM_NETWORK_CATEGORY_PRIVATE - uncommenting designates the connected network as "Private". 0 would set it as "Public". You need to be admin for this to have an effect
profileName := INetwork.GetName()
for k, v in INetwork.GetNetworkConnections() {
try if ((INetworkConnection := ComObjQuery(k, "{DCB00005-570F-4A9B-8D69-199FDBA5723B}"))) {
if (DllCall(NumGet(NumGet(INetworkConnection+0)+12*A_PtrSize), "Ptr", INetworkConnection, "Ptr", &adapterGuid) == 0) { ; ::GetAdapterId
if (DllCall("ole32\StringFromGUID2", "Ptr", &adapterGuid, "WStr", adapterGuidStr, "Int", 68)) {
adapterName := adapters[adapterGuidStr].Description
interfaceAlias := adapters[adapterGuidStr].FriendlyName
}
}
ObjRelease(INetworkConnection)
}
}
MsgBox % profileName . "`n" . adapterName . "`n" . interfaceAlias
}
; By just me: https://autohotkey.com/boards/viewtopic.php?t=18768
GetAdaptersAddresses()
{
; initial call to GetAdaptersAddresses to get the size needed
If (DllCall("iphlpapi.dll\GetAdaptersAddresses", "UInt", 2, "UInt", 0, "Ptr", 0, "Ptr", 0, "UIntP", Size) = 111) ; ERROR_BUFFER_OVERFLOW
If !(VarSetCapacity(Buf, Size, 0))
Return "Memory allocation failed for IP_ADAPTER_ADDRESSES struct"
; second call to GetAdapters Addresses to get the actual data we want
If (DllCall("iphlpapi.dll\GetAdaptersAddresses", "UInt", 2, "UInt", 0, "Ptr", 0, "Ptr", &Buf, "UIntP", Size) != 0) ; NO_ERROR
Return "Call to GetAdaptersAddresses failed with error: " . A_LastError
Addr := &Buf
Adapters := {}
While (Addr) {
AdapterName := StrGet(NumGet(Addr + 8, A_PtrSize, "Uptr"), "CP0")
Description := StrGet(NumGet(Addr + 8, A_PtrSize * 7, "UPtr"), "UTF-16")
FriendlyName := StrGet(NumGet(Addr + 8, A_PtrSize * 8, "UPtr"), "UTF-16")
Adapters[AdapterName] := {Description: Description, FriendlyName: FriendlyName}
Addr := NumGet(Addr + 8, "UPtr") ; *Next
}
Return Adapters
}