It is currently October 9th, 2024, 2:48 am

Finding your Network Interface for SysInfo and Net

Our most popular Tips and Tricks from the Rainmeter Team and others
User avatar
jsmorley
Developer
Posts: 22843
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Finding your Network Interface for SysInfo and Net

Post by jsmorley »

As of Rainmeter 4.5, we have changed how the SysInfo measure network options and Net (NetIn/NetOut/NetTotal) measures find the correct network interface / adapter to measure. This was done to make things more logical and consistent between the SysInfo and Net functionality, consolidate some internal coding for network functions, and increase efficiency of the code.

If you simply want to measure information about the currently active network interface on your system, it's very simple:

For SysInfo measures:
https://docs.rainmeter.net/manual/measures/sysinfo/#Network

Use: SysInfoData=Best

Code: Select all

[MeasureLAN]
Measure=SysInfo
SysInfoType=IP_ADDRESS
SysInfoData=Best
DynamicVariables=1
For Net measures:
https://docs.rainmeter.net/manual/measures/net/

Use: Interface=Best

Code: Select all

[MeasureNetIn]
Measure=NetIn
Interface=Best
DynamicVariables=1
The option value of "Best" will detect and measure the currently active interface. For almost all cases, this is what you want.

Note: There are cases where the meaning of "Best" can change while the skin is running. Most commonly this will be if you have a system, like a laptop, that has both wired (Ethernet) and wireless (WiFi) connections, and you switch between them. Another common case is if you have VPN software, that creates a "tunnel adapter" when running. In order to have your skin react to these changes, you must set DynamicVariables=1 on the measures.

Setting DynamicVariables=1 on the measures is recommended if you intend to "distribute" your skin, as while you might only have one network adapter, this may not be true of all your end-users.

Note that "Best" is now the default for both SysInfo and Net measures.


If you have two or more network interfaces that can be active at once:

In this case you are going to want to create separate SysInfo and / or Net measures to measure each of the interfaces. You certainly are going to want to at least be specific about which interface to measure. The recommended way to do this is to use the name (Description) of the actual network adapter in the measures.

There are many ways in Windows to find the Description of the network adapters, two ways are:

1) Turn on Debug mode and Log to file in the Settings panel in Rainmeter, and restart the application.
https://docs.rainmeter.net/manual/user-interface/manage/#Logging

The information about all your network interfaces will be in the log that is created. Be sure to turn both of these off when you are done with them.

Code: Select all

DBUG (08:04:32.360) :  46: Name: Intel(R) Dual Band Wireless-AC 7265
DBUG (08:04:32.361) :      Alias: Wi-Fi 3
DBUG (08:04:32.363) :      GUID: {18A8D6A0-64F9-4803-B4C5-329309490987}
DBUG (08:04:32.365) :      Type=Wireless(71), Hardware=Yes, Filter=No
DBUG (08:04:32.366) :      IfIndex=4, State=Connected, Status=Up(1)
Just copy and paste that "Name" information for use in the SysInfoData and / or Interface options.

Code: Select all

[MeasureLAN]
Measure=SysInfo
SysInfoType=IP_ADDRESS
SysInfoData=Intel(R) Dual Band Wireless-AC 7265
2) Perhaps a bit less cumbersome a way is to open a PowerShell (Windows Terminal) window and enter the following:

Get-NetAdapter | format-table -property "InterfaceDescription", "InterfaceIndex" -HideTableHeaders
https://docs.microsoft.com/en-us/powershell/module/netadapter/get-netadapter

Code: Select all

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\JSMorley> Get-NetAdapter | format-table -property "InterfaceDescription", "InterfaceIndex" -HideTableHeaders

TAP-NordVPN Windows Adapter V9                          20
Intel(R) I211 Gigabit Network Connection                13
NordLynx Tunnel                                         50
Intel(R) Dual Band Wireless-AC 7265                      4
Bluetooth Device (Personal Area Network) #2              3
There are other ways to format this PowerShell command to show more or less information as you like:

Get-NetAdapter -Name * -IncludeHidden | format-list -property "Name", "InterfaceDescription", "InterfaceIndex"

Code: Select all

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\JSMorley> Get-NetAdapter -Name * -IncludeHidden | format-list -property "Name", "InterfaceDescription", "InterfaceIndex"


Name                 : Local Area Connection* 8
InterfaceDescription : WAN Miniport (IPv6)
InterfaceIndex       : 25

Name                 : Local Area Connection* 2
InterfaceDescription : WAN Miniport (SSTP)
InterfaceIndex       : 23

Name                 : Local Area Connection* 7
InterfaceDescription : WAN Miniport (IP)
InterfaceIndex       : 22

Name                 : Ethernet 2
InterfaceDescription : TAP-NordVPN Windows Adapter V9
InterfaceIndex       : 20

Name                 : Local Area Connection* 9
InterfaceDescription : WAN Miniport (Network Monitor)
InterfaceIndex       : 19

Name                 : Teredo Tunneling Pseudo-Interface
InterfaceDescription :
InterfaceIndex       : 18

Name                 : Local Area Connection* 6
InterfaceDescription : WAN Miniport (PPPOE)
InterfaceIndex       : 17

Name                 : Local Area Connection* 3
InterfaceDescription : WAN Miniport (IKEv2)
InterfaceIndex       : 16

Name                 : Local Area Connection* 10
InterfaceDescription : Microsoft Wi-Fi Direct Virtual Adapter #2
InterfaceIndex       : 14

Name                 : Ethernet
InterfaceDescription : Intel(R) I211 Gigabit Network Connection
InterfaceIndex       : 13

Name                 : NordLynx
InterfaceDescription : NordLynx Tunnel
InterfaceIndex       : 50

Name                 : Local Area Connection* 1
InterfaceDescription : Microsoft Wi-Fi Direct Virtual Adapter
InterfaceIndex       : 10

Name                 : Local Area Connection* 4
InterfaceDescription : WAN Miniport (L2TP)
InterfaceIndex       : 8

Name                 : Microsoft IP-HTTPS Platform Interface
InterfaceDescription :
InterfaceIndex       : 7

Name                 : Local Area Connection* 5
InterfaceDescription : WAN Miniport (PPTP)
InterfaceIndex       : 6

Name                 : Ethernet (Kernel Debugger)
InterfaceDescription : Microsoft Kernel Debug Network Adapter
InterfaceIndex       : 5

Name                 : Wi-Fi 3
InterfaceDescription : Intel(R) Dual Band Wireless-AC 7265
InterfaceIndex       : 4

Name                 : Bluetooth Network Connection 2
InterfaceDescription : Bluetooth Device (Personal Area Network) #2
InterfaceIndex       : 3

Name                 : 6to4 Adapter
InterfaceDescription :
InterfaceIndex       : 2
Or if you want a full firehose of information about each interface:

Get-NetAdapter -Name * -IncludeHidden | format-list -property *


Using the network interface / adapter "index" number:

There is an interface index number that is created by Windows for each of your network interfaces. You can use this index number in the options for SysInfo and / or Net measures, but caution! These numbers are pretty dynamic in Windows and can change if you enable/disable networks. There is just no certainty that these numbers will remain constant over time.

Getting these numbers is the same as getting the name (Description) shown above, just use the number found as IfIndex in the Rainmeter log, or InterfaceIndex in the PowerShell output.


A backwards compatibility concern:

As originally written, the Net (NetIn/NetOut/NetTotal) measures will see an explicit index value of "0" as meaning "all". For systems with only one active interface, this sorta works well enough, and there may be skins out there that have Interface=0 or SysInfoData=0 on them. Those skins should be changed going forward. In most cases, it is recommended that they be changed to Interface=Best and SysInfoData=Best. If you have SysInfoData=0 on any measure, Rainmeter is going to automatically change it to "Best", but will bark at you in the log...
User avatar
CodeCode
Posts: 1391
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Finding your Network Interface

Post by CodeCode »

jsmorley wrote: September 16th, 2021, 12:32 pm
A backwards compatibility concern:

As originally written, the Net (NetIn/NetOut/NetTotal) measures will see an explicit index value of "0" as meaning "all". For systems with only one active interface, this sorta works well enough, and there may be skins out there that have Interface=0 or SysInfoData=0 on them. Those skins should be changed going forward. In most cases, it is recommended that they be changed to Interface=Best and SysInfoData=Best. If you have SysInfoData=0 on any measure, Rainmeter is going to automatically change it to "Best", but will bark at you in the log...
Yes. That was annoying - the barking... I kludged a fix. However with this guide, I think I can get things back to the background.

Or at least over time more consistent internet meters.

Thanks for this information.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
jsmorley
Developer
Posts: 22843
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Finding your Network Interface

Post by jsmorley »

CodeCode wrote: September 16th, 2021, 1:17 pm Yes. That was annoying - the barking... I kludged a fix. However with this guide, I think I can get things back to the background.

Or at least over time more consistent internet meters.

Thanks for this information.
Using "0" was really never a good idea. With Net measures it meant "all", but given that Windows has all kinds of obscure "virtual / tunnel" interfaces that can register "traffic" across them, using "0" could often cause "double" or even "triple" the values expected. As said, use "Best" in most cases, or just don't set SysInfoData / Interface at all, unless you have multiple "active" interfaces, in which case use the "Description". I pretty strongly recommend against ever using the numeric "index" number.
User avatar
Active Colors
Moderator
Posts: 1318
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: Finding your Network Interface for SysInfo and Net

Post by Active Colors »

Thank you!
User avatar
SilverAzide
Rainmeter Sage
Posts: 2744
Joined: March 23rd, 2015, 5:26 pm

Re: Finding your Network Interface

Post by SilverAzide »

The usefulness of interface indexes has actually been obsolete as of Rainmeter 3.3.0, when the SysInfo and NetIn/NetOut/NetTotal measures were enhanced to accept adapter names in addition to indexes.

The only significant "breaking change" (if you want to call it that), is that change to the interface index of "0", which used to mean "all" (but which now means "Best"). Using "0" has actually never worked properly, ever, in any version of Rainmeter, because of virtual network adapters. Using "0" would cause the NetIn/NetOut/NetTotal measures to report doubled/tripled/quadrupled/etc. values due to physical and virtual adapters all reporting the same traffic. So by doing away with this in Rainmeter 4.5, this has actually fixed a long-standing issue. The downside is that there is now no way to actually report "all" traffic, so skin authors will need to do additional work if this is actually what is desired.

Edit: Late to the party again... :)
Gadgets Wiki GitHub More Gadgets...
nikko
Posts: 46
Joined: December 5th, 2017, 5:58 pm

Re: Finding your Network Interface for SysInfo and Net

Post by nikko »

maybe a stupid question. Can SysInfoData and Interface always have the same values and to work properly?

example:
to control it with a variable
___________
NICVar=Best

[measure1]
...
SysInfoDate=#NICVar#

[measure2]
...
Interface=#NICVar#
User avatar
jsmorley
Developer
Posts: 22843
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Finding your Network Interface for SysInfo and Net

Post by jsmorley »

nikko wrote: September 27th, 2021, 8:53 pm maybe a stupid question. Can SysInfoData and Interface always have the same values and to work properly?

example:
to control it with a variable
___________
NICVar=Best

[measure1]
...
SysInfoDate=#NICVar#

[measure2]
...
Interface=#NICVar#
Certainly...