It is currently March 9th, 2021, 10:35 am

Detecting WAN and LAN connection status for individual network adapters

Help with creating, editing & fixing problems with skins
User avatar
Posts: 3017
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

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

Post by Yincognito »

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.
I see. Just tested it myself and it seems you are, at least partially, correct. It seems they only react correctly to the "global" internet connectivity, and not the "true" LAN one. In that case, maybe investigating the adapter's IP might be the closest you can get to have an idea about the connectivity of a particular adapter, like I explained above. Still not sure if the adapter having an IP assigned to it is a reliable way of getting its connectivity, but at least it's a start.
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?
Apparently not. It seems to work only for the internet connectivity. For LAN connectivity, the value returned seems to be the value of the internet connectivity and not the LAN one:

Code: Select all




Text="Adapter: %1#CRLF#Connected: %2"
Change [MeasureNICAdapterDescription]'s SysInfoData value to other adapters, and then change [MeasureInternet]'s SysInfoType value to INTERNET_CONNECTIVITY to see what I mean.
User avatar
Rainmeter Sage
Posts: 1143
Joined: March 23rd, 2015, 5:26 pm

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

Post by SilverAzide »

raiguard wrote: April 1st, 2019, 5:51 pmWhat 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.
I think you can partly do what you are looking for, maybe everything; but at worst I think you can at least get close.

First you can tackle LAN connectivity. Check out this command:
wmic nic where PhysicalAdapter=TRUE get AdapterType, Name, Description, NetEnabled, PhysicalAdapter

This will dump out a list of all the physical adapters on your system and tell you if they are up or not. If NetEnabled=TRUE then I think you will have LAN connectivity. There's Powershell commands...
Get-NetIPConfiguration -All -Detailed, or
Get-WmiObject -Class MSFT_NetAdapter -Namespace root\StandardCimv2
...that will give you gobs of info including all this NIC stuff, including the adapter status (Up, Disconnected, etc.). You can get IP addresses as well, so Yincognito's trick of looking for an address assigned to the adapter might help confirm LAN connectivity.

For WAN connectivity, I don't know of a way you can ping an external endpoint using a specific adapter. Sounds like something you'd have to do at a very low level. But I think you can assume that if an adapter can see your LAN (i.e., is "Up"), and Rainmeter's normal INTERNET_CONNECTIVITY SysInfo measure returns True, then I think you can assume that the adapter "could" reach the internet, even if it's not the one that "would".

So you can get close with a CommandMeasure calling Powershell or wmic, but that's not something you'd really want to do at one-second intervals....
Gadgets Wiki GitHub More Gadgets...