예제 #1
0
 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;;
 }
예제 #2
0
        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());
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
 internal static bool TryGetNetworkAdapter(PhysicalAddress macAddress, out ManagementObject networkAdapter)
 {
     networkAdapter = DNSHelper.GetNetworkAdapter(macAddress);
     return(networkAdapter != null);
 }
예제 #6
0
 internal static bool TryGetNetworkAdapter(string deviceName, out ManagementObject networkAdapter)
 {
     networkAdapter = DNSHelper.GetNetworkAdapter(deviceName);
     return(networkAdapter != null);
 }