It is currently March 28th, 2024, 11:39 am

Detecting WAN and LAN connection status for individual network adapters

Get help with creating, editing & fixing problems with skins
User avatar
raiguard
Posts: 660
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA
Contact:

Detecting WAN and LAN connection status for individual network adapters

Post by raiguard »

TL;DR:
How can I read WAN and LAN connection status for specific network adapters, rather than having to rely on SysInfo's LAN_CONNECTIVITY and WAN_CONNECTIVITY types?

Long-winded explanation (sorry):
Hello. I have a network skin which handles a wide variety of network things, including monitoring specific network adapters. I have an icon in the top-left which shows the network status:
2019-04-01 11_18_44-C__Files_Caleb_Development_Rainmeter_Testbench_Skins_ModernGadgets_NetworkMeter_.png
This icon is supposed to reflect the current network status. For example, if you are on ethernet but only connected to LAN, it will display a globe with an X in the corner:
2019-04-01 11_30_18-C__Files_Caleb_Development_Rainmeter_Testbench_Skins_ModernGadgets_NetworkMeter_.png
(I'm probably going to change this one, but that's not the point).

Rainmeter's measures for detecting WAN and LAN connection status look like this:

Code: Select all

[MeasureConnectedLan]
Measure=Plugin
Plugin=SysInfo
SysInfoType=LAN_CONNECTIVITY
OnChangeAction=[!UpdateMeasure MeasureNetworkIcon][!Log "LAN State changed"]

[MeasureConnectedWan]
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
OnChangeAction=[!UpdateMeasure MeasureNetworkIcon][!Log "WAN State changed"]
This works fine... for most people. For a small percentage of my userbase (including yours truly), it does not.

My PC has several extra "network adapters": an Xbox wireless adapter, and a Hamachi server, among other things. The above measures consider these to be network adapters, so even if I completely unplug my PC's ethernet cord and the WiFi adapter, it will still think it's connected to a LAN.

What I wish for is a way to detect WAN and LAN connectivity status for individual adapters. So my skin could check the ethernet adapter's status, and if that isn't connected for some reason, check the WiFi adapter. If that also isn't connected, it could display "no internet".

Is this possible? Thanks in advance.
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Detecting WAN and LAN connection status for individual network adapters

Post by Yincognito »

Well, I also have multiple network adapters, and generally, while global WAN connectivity is trivial to get (you just have to parse a simple webpage to see if you get something, use the OnConnectErrorAction of WebParser, or even use the Ping plugin to test the status), individual WAN connectivity is a different proposition (below the external/WAN IP and ping latency are retrieved, maybe you can use those to get the "global" WAN connectivity status):

Code: Select all

[MS_WebParser_EXTIP]
Measure=WebParser
Url=https://ident.me/.json
RegExp="(?siU)\{"address":.*"(.*)"\}"
UpdateRate=300
or

Code: Select all

[MS_Ping_Latency]
Measure=Plugin
Plugin=PingPlugin
DestAddress=8.8.8.8
UpdateRate=300
What I noticed is that usually, if an adapter is "connected", it will have an IP. Maybe you can use that to test for LAN connectivity, since you can get an adapter's IP on an individual basis using the SysInfoData option:

Code: Select all

[MS_SysInfo_NICIPAddress]
Measure=Plugin
Plugin=SysInfo
SysInfoType=IP_ADDRESS
SysInfoData=(name or index of the network interface here)
RegExpSubstitute=1
Substitute="(?:^\s+|\s+$)":"","(^$|^0$)":"Unavailable"
You can get each adapter's internal IP, then see if the adapters you got the info from have "LAN", "PCI"/"PCIe"/"PCI-E", "Wireless" or "WiFi"/"Wi-Fi" in their names in order to differentiate them from adapters like Xbox wireless adapters, Hamachi servers, Bluetooth devices, VirtualBox/VMWare adapters (the adapter's name is retrieved below):

Code: Select all

[MS_SysInfo_NICAdapterDescription]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=(index of the network interface here)
RegExpSubstitute=1
Substitute="(?:^\s+|\s+$)":"","(^$|^0$)":"Unavailable"
Me, I don't test for LAN or WAN connectivity, but if having an IP is an indicator of connectivity, you could iterate through all the NICs in the system using a measure like [MS_SysInfo_NICAdapterDescription] in order to get their names, then use those names to get the NICs IPs in a measure like [MS_SysInfo_NICIPAddress]. If the adapters having the substrings I mentioned above (could be more, of course) in their names have an IP, then you're "truly connected".

Of course, I could be wrong and having an IP wouldn't be a good indication of that adapter's connectivity, but this looks to me the best shot you could have at it so far. Maybe others will have better suggestions...
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Detecting WAN and LAN connection status for individual network adapters

Post by balala »

Yincognito wrote: April 3rd, 2019, 5:06 pm while global WAN connectivity is trivial to get (you just have to parse a simple webpage to see if you get something, use the OnConnectErrorAction of WebParser, or even use the Ping plugin to test the status),
Or you can use a SysInfo Plugin measure:

Code: Select all

[MeasureInternet]
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
SysInfoData=1
The above measure
Returns 1 if your computer is connected to the Internet, -1 if not.
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Detecting WAN and LAN connection status for individual network adapters

Post by Yincognito »

balala wrote: April 3rd, 2019, 5:48 pm Or you can use a SysInfo Plugin measure:

Code: Select all

[MeasureInternet]
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
SysInfoData=1
The above measure
True. I didn't mention this because I assumed he already explored this option, since he already used the SysInfoType=INTERNET_CONNECTIVITY option in his original post (though he never mentioned using the SysInfoData option, to get the connectivity for a specific adapter).
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Detecting WAN and LAN connection status for individual network adapters

Post by balala »

Yincognito wrote: April 3rd, 2019, 6:02 pm True. I didn't mention this because I assumed he already explored this option, since he already used the SysInfoType=INTERNET_CONNECTIVITY option in his original post (though he never mentioned using the SysInfoData option, to get the connectivity for a specific adapter).
Well, I have to admit, I didn't read all this topic, this is my fault. Just seeing your post I felt I have to post this third possibility too.
User avatar
Yincognito
Rainmeter Sage
Posts: 7017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Detecting WAN and LAN connection status for individual network adapters

Post by Yincognito »

balala wrote: April 3rd, 2019, 6:05 pm Well, I have to admit, I didn't read all this topic, this is my fault. Just seeing your post I felt I have to post this third possibility too.
No problem. After all, it was only an assumption - we don't know for sure if he tried already like this or not. ;-)
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Detecting WAN and LAN connection status for individual network adapters

Post by balala »

Yincognito wrote: April 3rd, 2019, 6:14 pm No problem. After all, it was only an assumption - we don't know for sure if he tried already like this or not. ;-)
Right! :great:
User avatar
raiguard
Posts: 660
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA
Contact:

Re: Detecting WAN and LAN connection status for individual network adapters

Post by raiguard »

Yincognito wrote: April 3rd, 2019, 6:02 pm True. I didn't mention this because I assumed he already explored this option, since he already used the SysInfoType=INTERNET_CONNECTIVITY option in his original post (though he never mentioned using the SysInfoData option, to get the connectivity for a specific adapter).
This doesn't work, those measures don't support the sysinfodata option. That's what I originally tried and it didn't work, which is the whole reason for making this post.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Detecting WAN and LAN connection status for individual network adapters

Post by balala »

raiguard wrote: April 3rd, 2019, 7:08 pm This doesn't work, those measures don't support the sysinfodata option. That's what I originally tried and it didn't work, which is the whole reason for making this post.
And if you add a SysInfoData option to the SysInfo plugin measure, setting the appropriate network interface controller (NIC)? Doesn't help?
User avatar
raiguard
Posts: 660
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA
Contact:

Re: Detecting WAN and LAN connection status for individual network adapters

Post by raiguard »

balala wrote: April 3rd, 2019, 7:16 pm And if you add a SysInfoData option to the SysInfo plugin measure, setting the appropriate network interface controller (NIC)? Doesn't help?
Nope. That's what I originally tried because I assumed that it would work, but it doesn't. For every SysInfoType that uses SysInfoData, the documentation specifically states what SysInfoData will do. LAN_CONNECTIVITY and INTERNET_CONNECTIVITY don't have any details on this, so I assume it's intentional.

Maybe it would be possible to add this feature?
Post Reply