diff --git a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs index 44e27d7..9389928 100644 --- a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs +++ b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs @@ -40,6 +40,22 @@ namespace ICD.Common.Utils } } + /// + /// Gets the mac address(es) of the processor. + /// + [PublicAPI] + public static IEnumerable MacAddresses + { + get + { + const CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET param = + CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS; + const EthernetAdapterType type = EthernetAdapterType.EthernetLANAdapter; + short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type); + yield return CrestronEthernetHelper.GetEthernetParameter(param, id); + } + } + #region Methods public static DateTime GetLocalTime() diff --git a/ICD.Common.Utils/IcdEnvironment.Standard.cs b/ICD.Common.Utils/IcdEnvironment.Standard.cs index db69d5a..e852ba6 100644 --- a/ICD.Common.Utils/IcdEnvironment.Standard.cs +++ b/ICD.Common.Utils/IcdEnvironment.Standard.cs @@ -4,31 +4,66 @@ using System.Collections.Generic; using System.Linq; using System.Net.NetworkInformation; using System.Net.Sockets; +using System.Text.RegularExpressions; +using ICD.Common.Properties; namespace ICD.Common.Utils { - public static partial class IcdEnvironment - { - public static string NewLine { get { return Environment.NewLine; } } + public static partial class IcdEnvironment + { + public static string NewLine { get { return Environment.NewLine; } } - public static DateTime GetLocalTime() - { - return DateTime.Now; - } + public static DateTime GetLocalTime() + { + return DateTime.Now; + } - public static eRuntimeEnvironment RuntimeEnvironment { get { return eRuntimeEnvironment.Standard; } } - - public static IEnumerable NetworkAddresses - { - get - { + public static eRuntimeEnvironment RuntimeEnvironment { get { return eRuntimeEnvironment.Standard; } } + + /// + /// Gets the network address(es) of the processor. + /// + [PublicAPI] + public static IEnumerable NetworkAddresses + { + get + { return NetworkInterface.GetAllNetworkInterfaces() - .Where(ni => ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) - .SelectMany(ni => ni.GetIPProperties().UnicastAddresses - .Where(ua => ua.Address.AddressFamily == AddressFamily.InterNetwork) - .Select(ua => ua.Address.ToString())); - } - } - } + .Where(ni => ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || + ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) + .SelectMany(ni => ni.GetIPProperties().UnicastAddresses + .Where(ua => ua.Address.AddressFamily == AddressFamily.InterNetwork) + .Select(ua => ua.Address.ToString())); + } + } + + /// + /// Gets the mac address(es) of the processor. + /// + [PublicAPI] + public static IEnumerable MacAddresses + { + get + { + return NetworkInterface.GetAllNetworkInterfaces() + .Where(ni => ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || + ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) + .Select(ni => ni.GetPhysicalAddress().ToString()) + .Select(FormatMacAddress); + } + } + + /// + /// Converts 12 digit address to XX:XX:XX... format + /// + /// + /// + private static string FormatMacAddress(string address) + { + const string regex = "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})"; + const string replace = "$1:$2:$3:$4:$5:$6"; + return Regex.Replace(address, regex, replace); + } + } } #endif