The Slascone.Client.DeviceInfos namespace provides platform-specific helper classes for retrieving hardware and system identifiers, detecting virtualization and cloud environments, and gathering network interface information.
These utilities help generate a stable and unique client_id for SLASCONE license activations and heartbeats.
For background on how device identifiers are used in SLASCONE licensing, see:
WINDOWS DEVICE INFOS
WindowsDeviceInfos is a static class that retrieves Windows-specific device identifiers using WMI.
Platform: Windows only
Namespace: Slascone.Client.DeviceInfos
ComputerSystemProductId
Returns the UUID of the computer system product as reported by the WMI class Win32_ComputerSystemProduct.
public static string ComputerSystemProductId { get; }
Returns
A string containing the UUID of the computer system product.
Remarks
- This UUID is hardware-based and stable across OS reinstalls.
- It is a good candidate for use as a
client_id. - Requires Windows WMI access and is not available on Linux.
OperatingSystem
Returns the name and version of the Windows operating system.
public static string OperatingSystem { get; }
Returns
A human-readable string combining the OS name and version. Returns "Windows" if an error occurs.
Remarks
- This value can change when the OS is updated and is therefore not suitable as a
client_id. - Use it for descriptive fields such as
operating_systemin heartbeats or for analytics.
LogDeviceInfos
Collects and formats available Windows device information into a diagnostic string.
public static string LogDeviceInfos()
Returns
A formatted, multi-line string containing device and network information.
Remarks
- Useful for log files, support dialogs, or diagnostic reports.
- Internally uses
NetworkInterfacesInfos.MacAddressesandNetworkInterfacesInfos.LogNetworkInterfaces.
LINUX DEVICE INFOS
LinuxDeviceInfos is a static class that retrieves Linux-specific identifiers from system files and command-line tools.
Platform: Linux only
Namespace: Slascone.Client.DeviceInfos
MachineId
Returns the machine ID from /etc/machine-id.
public static string MachineId { get; }
Returns
A string containing the machine ID, null if the file does not exist, or an empty string if an error occurs.
Remarks
- The machine ID is generated during OS installation and remains stable across reboots.
- It can change if the OS is reinstalled.
- It is a common candidate for use as a
client_idon Linux, especially when DMI data is not available.
HostId
Returns the hostname via uname -n.
public static string HostId { get; }
Returns
The hostname of the system, or an empty string if the command fails.
Remarks
- The hostname can be changed by administrators and is not suitable as a
client_idon its own. - It may be useful as a descriptive label.
Hostname
Returns the value of the HOSTNAME environment variable.
public static string Hostname { get; }
Returns
The value of the HOSTNAME environment variable, or null if it is not set.
Remarks
- Useful in containerized environments where
HOSTNAMEis often set to the container ID. - Not suitable as a stable
client_idbecause it can change between container restarts.
OSVersion
Returns operating system version information via uname -morsv.
public static string OSVersion { get; }
Returns
A string combining machine hardware name, operating system, kernel release, kernel name, and kernel version.
Remarks
- This value can change when the kernel is updated and is therefore not suitable as a
client_id. - Use it for descriptive fields or analytics.
DockerEnvExists
Indicates whether the application is running inside a Docker container.
public static bool DockerEnvExists { get; }
Returns
true if /.dockerenv exists; otherwise, false.
Remarks
- This is a quick heuristic for Docker detection and is not definitive for all container runtimes.
- It can help decide which identification strategy to use.
IsDmiAvailable
Indicates whether DMI data is accessible.
public static bool IsDmiAvailable { get; }
Returns
true if /sys/class/dmi exists; otherwise, false.
Remarks
- DMI data is typically available on physical and virtual machines.
- DMI data may not be available in containers.
- Check this property before accessing
DmiProductUuid.
DmiProductUuid
Returns the product UUID from /sys/class/dmi/id/product_uuid.
public static string DmiProductUuid { get; }
Returns
The product UUID, null if DMI is not available, or an empty string if an error occurs.
Remarks
- This is a hardware-assigned UUID and is a good candidate for use as a
client_idon Linux. - Reading this file may require elevated permissions.
- It is usually not available in container environments.
RootDeviceSerial
Returns the serial number of the block device that contains the root file system.
public static string RootDeviceSerial { get; }
Returns
The serial number of the root block device, or an empty string if it is not available.
Remarks
- Requires the
lsblkcommand. - This is a hardware-based identifier and can be used as one component of a
client_id.
RootPartitionUuid
Returns the UUID of the partition mounted as the root file system.
public static string RootPartitionUuid { get; }
Returns
The UUID of the root partition, or an empty string if it is not available.
Remarks
- Determined via
lsblkby finding the partition with mount point/. - Partition UUIDs are stable unless the partition is reformatted.
LogDeviceInfos
Collects and formats available Linux device information into a diagnostic string.
public static string LogDeviceInfos()
Returns
A formatted, multi-line string containing Linux device and network information.
Remarks
- Useful for log files, support dialogs, and diagnostic reports.
- Internally uses
NetworkInterfacesInfosand block device information.
NETWORK INTERFACE INFOS
NetworkInterfacesInfos provides cross-platform information about network interfaces and adapters.
Platform: Cross-platform. Virtual adapter detection is Windows-only.
Namespace: Slascone.Client.DeviceInfos
MacAddresses
Returns a dictionary mapping network interface names to MAC addresses.
public static IDictionary<string, string> MacAddresses(bool includeVirtual = false)
Parameters
| Parameter | Type | Description |
|---|---|---|
includeVirtual |
bool |
If true, includes virtual network adapters. Default is false. |
Returns
A dictionary where the key is the network interface name and the value is the MAC address.
Remarks
- Only interfaces with
OperationalStatus.Upare included. - On Windows, virtual adapter detection uses WMI.
- MAC addresses can be used as one component of a composite
client_id.
LogNetworkInterfaces
Formats detailed information about all network interfaces into a diagnostic string.
public static string LogNetworkInterfaces(string prefix = null)
Parameters
| Parameter | Type | Description |
|---|---|---|
prefix |
string |
An optional prefix prepended to each output line. |
Returns
A formatted, multi-line string listing network interface details.
IsVirtual
Determines whether a network adapter is virtual.
public static bool? IsVirtual(string name)
Parameters
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name of the network adapter to check. |
Returns
true if the adapter is virtual, false if it is physical, or null if this cannot be determined.
Remarks
- Windows only. Uses WMI to query the virtual adapter status.
- On non-Windows platforms, this method returns
null.
VIRTUALIZATION INFOS
VirtualizationInfos detects whether the application is running inside a virtual machine and identifies the hypervisor type.
Platform: Windows and Linux
Namespace: Slascone.Client.DeviceInfos
Constructor
public VirtualizationInfos()
Creates a new instance. Detection is not performed until DetectVirtualization is called or VirtualizationType is accessed.
DetectVirtualization
Detects whether the current environment is virtualized.
public async Task<bool> DetectVirtualization()
Returns
true if virtualization is detected; otherwise, false.
Remarks
- On Windows, detection uses WMI classes such as
Win32_BaseBoard,Win32_BIOS, andWin32_ComputerSystem. - On Linux, detection uses DMI data, CPU information, and system commands.
- Throws
InvalidOperationExceptionon unsupported platforms.
VirtualizationType
Returns a description of the detected virtualization technology.
public string VirtualizationType { get; }
Returns
A string describing the hypervisor or virtualization type. Returns an empty string if no virtualization was detected.
Remarks
- Accessing this property triggers virtualization detection synchronously if it has not been called yet.
- Useful for analytics, diagnostics, and determining whether hardware-based identifiers are reliable.
AWS EC2 INFOS
AwsEc2Infos detects an AWS EC2 environment and provides access to the Instance Identity Document through the Instance Metadata Service.
Platform: Cross-platform on EC2 instances
Namespace: Slascone.Client.DeviceInfos
Constructor
public AwsEc2Infos()
Creates a new instance. Detection is not performed until DetectAwsEcs is called.
TimeoutSeconds
Gets or sets the timeout in seconds for metadata service requests.
public int TimeoutSeconds { get; set; }
Default: 10 seconds.
DetectAwsEcs
Attempts to detect an AWS EC2 environment by requesting an Instance Identity Document from the metadata service.
public async Task<bool> DetectAwsEcs()
Returns
true if an AWS EC2 environment was detected; otherwise, false.
Remarks
- Uses IMDSv2 token-based authentication.
- If this method returns
false, all metadata property accessors throwInvalidOperationException. - On non-EC2 environments, the metadata request will time out.
Instance Identity Properties
After a successful call to DetectAwsEcs, instance identity properties such as InstanceId, AccountId, Region, InstanceType, and ImageId are available.
The InstanceId is unique within AWS and is a suitable client_id for EC2-based deployments.
AZURE VM INFOS
AzureVmInfos detects an Azure VM environment and provides access to Azure Instance Metadata Service compute metadata.
Platform: Cross-platform on Azure VMs
Namespace: Slascone.Client.DeviceInfos
Constructor
public AzureVmInfos()
Creates a new instance. Detection is not performed until DetectAzureVm is called.
TimeoutSeconds
Gets or sets the timeout in seconds for metadata service requests.
public int TimeoutSeconds { get; set; }
Default: 10 seconds.
DetectAzureVm
Attempts to detect an Azure VM environment by querying the Instance Metadata Service.
public async Task<bool> DetectAzureVm()
Returns
true if an Azure VM environment was detected; otherwise, false.
Remarks
- Uses the Azure metadata endpoint at
169.254.169.254. - If this method returns
false, all metadata property accessors throwInvalidOperationException. - On non-Azure environments, the metadata request will time out.
Instance Metadata Properties
After a successful call to DetectAzureVm, VM metadata properties such as VmId, Name, SubscriptionId, ResourceGroupName, Location, VmSize, and OsType are available.
The VmId is unique within Azure and is a suitable client_id for Azure VM-based deployments.
CHOOSING THE RIGHT IDENTIFIER
When selecting a value for the client_id parameter in SLASCONE license activations and heartbeats, prefer identifiers that are stable, unique, and difficult to change accidentally.
| Environment | Recommended Identifier | Property | Stability |
|---|---|---|---|
| Windows physical machine | WMI Computer System Product UUID | WindowsDeviceInfos.ComputerSystemProductId |
Stable across OS reinstalls |
| Linux physical machine | DMI Product UUID | LinuxDeviceInfos.DmiProductUuid |
Stable, may require elevated permissions |
| Linux without DMI | Machine ID | LinuxDeviceInfos.MachineId |
Stable per OS installation |
| AWS EC2 | Instance ID | AwsEc2Infos.InstanceId |
Stable for the instance lifetime |
| Azure VM | VM ID | AzureVmInfos.VmId |
Stable for the VM lifetime |
| Docker or container | HOSTNAME environment variable | LinuxDeviceInfos.Hostname |
Changes per container instance |
| Any platform | MAC address | NetworkInterfacesInfos.MacAddresses() |
Stable for physical adapters |
PROPERTIES NOT SUITABLE AS CLIENT_ID
The following properties are descriptive and can change over time. Use them for informational fields such as operating_system in heartbeats or for analytics, but not as the primary client_id:
WindowsDeviceInfos.OperatingSystemLinuxDeviceInfos.OSVersionLinuxDeviceInfos.HostIdVirtualizationInfos.VirtualizationType
DIAGNOSTIC LOGGING
Both WindowsDeviceInfos.LogDeviceInfos() and LinuxDeviceInfos.LogDeviceInfos() produce a comprehensive dump of available identifiers and system information. Use these methods during application startup or when generating support information to diagnose device identification issues.
// Example: Log device information for diagnostics
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Console.WriteLine(WindowsDeviceInfos.LogDeviceInfos());
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Console.WriteLine(LinuxDeviceInfos.LogDeviceInfos());
Comments
0 comments
Article is closed for comments.