It is currently April 25th, 2024, 4:10 am

Detecting WAN and LAN connection status for individual network adapters

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7157
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

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureNICAdapterDescription]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=1
RegExpSubstitute=1
Substitute="(?:^\s+|\s+$)":"","(^$|^0$)":"Unavailable"
DynamicVariables=1

[MeasureInternet]
Measure=Plugin
Plugin=SysInfo
SysInfoType=LAN_CONNECTIVITY
SysInfoData=[MeasureNICAdapterDescription]
DynamicVariables=1

[MeterRun]
Meter=String
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
MeasureName=MeasureNICAdapterDescription
MeasureName2=MeasureInternet
Text="Adapter: %1#CRLF#Connected: %2"
DynamicVariables=1
Change [MeasureNICAdapterDescription]'s SysInfoData value to other adapters, and then change [MeasureInternet]'s SysInfoType value to INTERNET_CONNECTIVITY to see what I mean.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
SilverAzide
Rainmeter Sage
Posts: 2605
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...