Ejemplo n.º 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;;
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }