mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 12:45:01 +00:00
Features for getting system mac addresses
This commit is contained in:
@@ -40,6 +40,22 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the mac address(es) of the processor.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static IEnumerable<string> 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
|
#region Methods
|
||||||
|
|
||||||
public static DateTime GetLocalTime()
|
public static DateTime GetLocalTime()
|
||||||
|
|||||||
@@ -4,31 +4,66 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using ICD.Common.Properties;
|
||||||
|
|
||||||
namespace ICD.Common.Utils
|
namespace ICD.Common.Utils
|
||||||
{
|
{
|
||||||
public static partial class IcdEnvironment
|
public static partial class IcdEnvironment
|
||||||
{
|
{
|
||||||
public static string NewLine { get { return Environment.NewLine; } }
|
public static string NewLine { get { return Environment.NewLine; } }
|
||||||
|
|
||||||
public static DateTime GetLocalTime()
|
public static DateTime GetLocalTime()
|
||||||
{
|
{
|
||||||
return DateTime.Now;
|
return DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static eRuntimeEnvironment RuntimeEnvironment { get { return eRuntimeEnvironment.Standard; } }
|
public static eRuntimeEnvironment RuntimeEnvironment { get { return eRuntimeEnvironment.Standard; } }
|
||||||
|
|
||||||
public static IEnumerable<string> NetworkAddresses
|
/// <summary>
|
||||||
{
|
/// Gets the network address(es) of the processor.
|
||||||
get
|
/// </summary>
|
||||||
{
|
[PublicAPI]
|
||||||
|
public static IEnumerable<string> NetworkAddresses
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
return NetworkInterface.GetAllNetworkInterfaces()
|
return NetworkInterface.GetAllNetworkInterfaces()
|
||||||
.Where(ni => ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
|
.Where(ni => ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
|
||||||
.SelectMany(ni => ni.GetIPProperties().UnicastAddresses
|
ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
|
||||||
.Where(ua => ua.Address.AddressFamily == AddressFamily.InterNetwork)
|
.SelectMany(ni => ni.GetIPProperties().UnicastAddresses
|
||||||
.Select(ua => ua.Address.ToString()));
|
.Where(ua => ua.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||||
}
|
.Select(ua => ua.Address.ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the mac address(es) of the processor.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static IEnumerable<string> MacAddresses
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return NetworkInterface.GetAllNetworkInterfaces()
|
||||||
|
.Where(ni => ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
|
||||||
|
ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
|
||||||
|
.Select(ni => ni.GetPhysicalAddress().ToString())
|
||||||
|
.Select(FormatMacAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts 12 digit address to XX:XX:XX... format
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="address"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user