private void InitializeNetworkAdapters(ManagementObject networkAdapter, NetworkInterface networkInterface = null) { this.networkAdapter = networkAdapter; this.networkInterface = networkInterface ?? DNSHelper.GetNetworkInterface(this.networkAdapter.GetPropertyValue <string>("Description")); this.MACAddress = this.networkAdapter.GetPropertyValue <string>("MACAddress").ToPhysicalAddress().GetAddressBytes(); this.DNSConfiguration = this.GetDNSConfiguration(); this.IPAddress = IPAddress.Parse(this.networkAdapter.GetPropertyValue <string[]>("IPAddress").FirstOrDefault()); this.DeviceName = this.networkInterface.Description;; }
public static NetworkAdapterInfo[] GetAdapters() { List <NetworkAdapterInfo> returnValue = new List <NetworkAdapterInfo>(); var adaptors = DNSHelper.GetAvailableNetworkAdapters(); foreach (var adaptor in adaptors) { NetworkInterface networkInterface; var macAddress = adaptor.GetPropertyValue <string>("MACAddress").ToPhysicalAddress(); if (DNSHelper.TryGetNetworkInterface(macAddress, out networkInterface)) { returnValue.Add(NetworkAdapterInfo.Create(adaptor, networkInterface)); } } return(returnValue.ToArray()); }
public NetworkAdapterInfo(PhysicalAddress macAddress) : this() { if (macAddress == null) { throw new ArgumentNullException(nameof(macAddress)); } var networkAdapter = DNSHelper.GetNetworkAdapter(macAddress); var networkInterface = DNSHelper.GetNetworkInterface(macAddress); if (networkAdapter == null || networkInterface == null) { throw new ArgumentException($"The device '{macAddress} can not be found."); } this.InitializeNetworkAdapters(networkAdapter, networkInterface); }
/// <summary> /// Initializes a new instance of the <see cref="NetworkAdapterInfo"/> class, from the specified <paramref name="networkAdapter"/> instance. /// </summary> /// <param name="deviceName">An string value identifing the name of the device of network adapter.</param> /// <exception cref="ArgumentNullException">thrown if the <paramref name="deviceName"/> is <c>Null</c> or <c>Blank</c>.</exception> /// <exception cref="ArgumentException">thrown if the specified <paramref name="deviceName"/> is does not belong to a matching network device.</exception> public NetworkAdapterInfo(string deviceName) : this() { if (string.IsNullOrWhiteSpace(deviceName)) { throw new ArgumentNullException(nameof(deviceName)); } var networkAdapter = DNSHelper.GetNetworkAdapter(deviceName); var networkInterface = DNSHelper.GetNetworkInterface(deviceName); if (networkAdapter == null || networkInterface == null) { throw new ArgumentException($"The device '{deviceName} can not be found."); } this.InitializeNetworkAdapters(networkAdapter, networkInterface); }
internal static bool TryGetNetworkAdapter(PhysicalAddress macAddress, out ManagementObject networkAdapter) { networkAdapter = DNSHelper.GetNetworkAdapter(macAddress); return(networkAdapter != null); }
internal static bool TryGetNetworkAdapter(string deviceName, out ManagementObject networkAdapter) { networkAdapter = DNSHelper.GetNetworkAdapter(deviceName); return(networkAdapter != null); }