Function to get interface user-defined name?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Nov 9, 2016
24
0
Netherlands
#1
Hello all.

Maybe I'm missing something, but I can't figure it out...

I'm trying to retrieve the interface names that I assigned.
(on Win7, Network connections, and F2 on a specific adapter to rename it)

If I use %@IPNAMEN[n], then I get names like :

{DAE8366E-2855-4154-A56F-3957062BEE1F}
{F6F7C705-D880-4C35-A2B0-CD6714B587E1}
{540FD87B-6A0D-411C-BFDE-DEEF77FDD6E6}

Those are technically correct, but not the names I'm looking for.

If I use %@IPALIASES[n], I get an empty string.

This is also correct, since in Windows, an alias is actually a different IP config for the same adapter, so it's not just limited to the interface name.

If I use %@IPDESC[n], I get this :

Realtek PCIe GBE Family Controller
DisplayLink Ethernet
Qualcomm Atheros QCA9565 802.11b/g/n WiFi Adapter

Again, also true but not the names I'm looking for.

So short of using %@EXECSTR[NETSH...], if there a built-in function to get me this info?

Thanks.
x13
 
#2
Not completely sure, but my guess is you want information about network *connections* instead of information about *adapters* (physical/virtual NIC's).

Network connections include beside an adapter also the bindings with network protocol and network client.

I never used the %@IP functions before, but after a quick glance I could not find *connection* related functions.
You could read them from the registry, though:

Code:
echo %@regquery[HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%@IPNAMEN[n]\Connection\Name]

Local Area Connection
Where {4D36E972-E325-11CE-BFC1-08002BE10318} is the GUID of the Net Class (fixed Microsoft GUID)
and [n] is the index of the adapter. In my case it was [0]



Or use a %@WMI query. For inspiration:
Code:
WMIC.exe NIC | view
 
Nov 9, 2016
24
0
Netherlands
#3
Not completely sure, but my guess is you want information about network *connections* instead of information about *adapters* (physical/virtual NIC's).

Network connections include beside an adapter also the bindings with network protocol and network client.

I never used the %@IP functions before, but after a quick glance I could not find *connection* related functions.
You could read them from the registry, though:

Code:
echo %@regquery[HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%@IPNAMEN[n]\Connection\Name]

Local Area Connection
Where {4D36E972-E325-11CE-BFC1-08002BE10318} is the GUID of the Net Class (fixed Microsoft GUID)
and [n] is the index of the adapter. In my case it was [0]



Or use a %@WMI query. For inspiration:
Code:
WMIC.exe NIC | view
Of
 
Nov 9, 2016
24
0
Netherlands
#4
Natuuuuurlijk!

How silly of me.

So the missing function can be added thus :

FUNCTION IPCONNECTION=`%@REGQUERY[HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%@IPNAMEN[%1]\Connection\Name]`

DO x=0 TO %_IPADAPTERS (ECHO %x = %@IPCONNECTION[%x])
0 = BT_PAN
1 = LAN
2 = DLINK
3 = WLAN
4 = TAP
5 = VMnet1
6 = VMnet8

Works a treat! Thanks.


I actually wanted to write this piece of code for a related problem...
One of my BTMs checks the connection status of a given interface using NETSH (via %@EXECTSTR).

But for an unknown reason, the one I called "WLAN" is half-no longer recognised by NETSH (though it's in the registry and also appears in the network interfaces correctly). I get this result also using NETSH directly btw.

This is what I mean :

NETSH INTERFACE SHOW INTERFACE NAME=WLAN

WLAN
Type: Dedicated
Administrative state: Enabled
Connect state: Disconnected



NETSH INTERFACE IP SHOW INTERFACE WLAN
Element not found

Whereas another user-defined interface shows normal info.

NETSH INTERFACE IP SHOW INTERFACE LAN

Interface LAN Parameters
----------------------------------------------
IfLuid : ethernet_30
IfIndex : 28
State : connected
Metric : 10
Link MTU : 1500 bytes
[...]


I know this has nothing to do with TCC, but as long as we're on the subject, perhaps someone can tell me where to look.
It's most likely a stale registry entry, but I don't want to mess arround too much with those as it can f*%-up the network config.
I learned my lesson the last time.

Thanks.

Mark/x13
 
#5
For some strange reason WLAN has it's own NETSH "interface".
Try:

Code:
NETSH WLAN Show Interfaces
(Can't test this right now, but it *should* give you a connection status)
 
#11
NETSH INTERFACE IP SHOW INTERFACE WLAN works here .. ("WLAN" = "Wi-Fi" in my case)

First thing that comes to mind is that the WLAN network isn't managed through Windows, but by a utility provided by the hardware manufacturer (most laptop manufacturers have their own utility). This might bypass the Windows mechanism.