Simple example to dump MAC addresses of physical adapters as candidates for a fixed identity, for example to use for licensing.
It lists available MAC addresses which are likely to by physical adapters that are unlikely to change, and also inactive adapters for diagnostics. It filters out virtual, tunnel, dummy and similar adapters. The first in the list should typically be best candidate for licensing.
On Linux the checks for an active adapter with gateway address may not work, but normally there is an 'eth0' adapter as primary which is typically reliable for a fixed MAC address, so will look for eth0 or an 'altname' of eth0 if supported on the OS (RHEL 8.5+ for example)
On Windows it can also run a legacy method querying using WMI if the argument --legacy is provided
dotnet build
Publishes by default as a single file executable, framework dependent requiring the relevant runtime installed. This is done to keep the executable size minimal.
The runtime identifier (RID) is required for the target platform for this kind of build.
For example:
dotnet publish -c Release -r win-x64 for Windows x64
dotnet publish -c Release -r linux-x64 for Linux x64
Alternatively to build self-contained including the runtime, for example dotnet publish -c Release -r linux-x64 --self-contained true. This will produce a much bigger executable.
To run the published executable, simply run from publish folder (Linux shells or PowerShell. Append .exe on Windows for Command Prompt shell):
./MacList
chmod +x Maclist may be required on Linux