Ejemplo n.º 1
0
        /// <summary>
        /// Returns true if Location instances are equal
        /// </summary>
        /// <param name="other">Instance of Location to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Location other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Uuid == other.Uuid ||
                     Uuid != null &&
                     Uuid.Equals(other.Uuid)
                     ) &&
                 (
                     Identifier == other.Identifier ||
                     Identifier != null &&
                     Identifier.Equals(other.Identifier)
                 ) &&
                 (
                     Status == other.Status ||
                     Status != null &&
                     Status.Equals(other.Status)
                 ) &&
                 (
                     OperationalStatus == other.OperationalStatus ||
                     OperationalStatus != null &&
                     OperationalStatus.Equals(other.OperationalStatus)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Alias == other.Alias ||
                     Alias != null &&
                     Alias.SequenceEqual(other.Alias)
                 ) &&
                 (
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                 ));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取当前本地连接列表,根据网络接口类型,和操作状态
        /// </summary>
        /// <param name="type">网络接口类型</param>
        /// <param name="ipEnabled">网络接口的操作状态</param>
        public static List<NetworkVO> GetNetworkList(NetworkInterfaceType type, OperationalStatus status)
        {
            List<NetworkVO> list = new List<NetworkVO>();
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                //过滤网络接口类型
                if (!NetworkInterfaceType.Unknown.Equals(type) && !type.Equals(adapter.NetworkInterfaceType))
                {
                    logger.Debug("跳过的其他类型网络,name=" + adapter.Name + ", NetworkInterfaceType=" + adapter.NetworkInterfaceType + ", OperationalStatus=" + adapter.OperationalStatus);
                    continue;
                }
                //过滤网络接口的操作状态
                if (!status.Equals(adapter.OperationalStatus))
                {
                    logger.Debug("跳过的不是上行网络,name=" + adapter.Name + ", NetworkInterfaceType=" + adapter.NetworkInterfaceType + ", OperationalStatus=" + adapter.OperationalStatus);
                    continue;
                }
                NetworkVO vo = new NetworkVO();
                vo.IpEnabled = true;
                IPInterfaceProperties property = adapter.GetIPProperties();
                vo.DnsHostName = Dns.GetHostName();//本机名
                vo.Name = adapter.Name;
                vo.Description = adapter.Description;
                vo.Speed = adapter.Speed;

                //macAddress
                if (adapter.GetPhysicalAddress() != null && adapter.GetPhysicalAddress().ToString().Length > 0)
                {
                    char[] mac = adapter.GetPhysicalAddress().ToString().ToCharArray();
                    vo.MacAddress = mac[0] + mac[1] + "-" + mac[2] + mac[3] + "-" + mac[4] + mac[5] + "-" + mac[6] + mac[7] + "-" + mac[8] + mac[9] + "-" + mac[10] + mac[11];
                }

                //ipAddress subnetMask 
                if (property.UnicastAddresses != null && property.UnicastAddresses.Count > 0)
                {
                    foreach (UnicastIPAddressInformation ip in property.UnicastAddresses)
                    {
                        if (ip.Address.AddressFamily.Equals(AddressFamily.InterNetwork))
                        {
                            if (ip.Address != null)
                            {
                                vo.Address = ip.Address.ToString();
                            }
                            if (ip.IPv4Mask != null)
                            {
                                vo.SubnetMask = ip.IPv4Mask.ToString();
                            }
                        }
                    }
                }

                // gateway
                if (property.GatewayAddresses != null && property.GatewayAddresses.Count > 0)
                {
                    foreach (GatewayIPAddressInformation uip in property.GatewayAddresses)
                    {
                        if (uip.Address.AddressFamily.Equals(AddressFamily.InterNetwork))
                        {
                            vo.Gateway = uip.Address.ToString();
                        }
                    }
                }

                // dns server
                if (property.DnsAddresses != null && property.DnsAddresses.Count > 0)
                {
                    vo.DnsServers = new List<string>();
                    foreach (IPAddress ip in property.DnsAddresses)
                    {
                        if (ip.AddressFamily.Equals(AddressFamily.InterNetwork))
                        {
                            vo.DnsServers.Add(ip.ToString());
                        }
                    }
                }

                // dhcp server
                if (property.DhcpServerAddresses != null && property.DhcpServerAddresses.Count > 0)
                {
                    foreach (IPAddress ip in property.DhcpServerAddresses)
                    {
                        if (ip.AddressFamily.Equals(AddressFamily.InterNetwork))
                        {
                            vo.DhcpServer = ip.ToString();
                            vo.DhcpEnabled = true;
                        }
                    }
                }
                else
                {
                    vo.DhcpEnabled = false;
                }
                list.Add(vo);
            }
            return list;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取当前本地连接列表,根据网络接口类型,和操作状态
        /// </summary>
        /// <param name="type">网络接口类型</param>
        /// <param name="ipEnabled">网络接口的操作状态</param>
        public static List <NetworkVO> GetNetworkList(NetworkInterfaceType type, OperationalStatus status)
        {
            List <NetworkVO> list = new List <NetworkVO>();

            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                //过滤网络接口类型
                if (!NetworkInterfaceType.Unknown.Equals(type) && !type.Equals(adapter.NetworkInterfaceType))
                {
                    logger.Debug("跳过的其他类型网络,name=" + adapter.Name + ", NetworkInterfaceType=" + adapter.NetworkInterfaceType + ", OperationalStatus=" + adapter.OperationalStatus);
                    continue;
                }
                //过滤网络接口的操作状态
                if (!status.Equals(adapter.OperationalStatus))
                {
                    logger.Debug("跳过的不是上行网络,name=" + adapter.Name + ", NetworkInterfaceType=" + adapter.NetworkInterfaceType + ", OperationalStatus=" + adapter.OperationalStatus);
                    continue;
                }
                NetworkVO vo = new NetworkVO();
                vo.IpEnabled = true;
                IPInterfaceProperties property = adapter.GetIPProperties();
                vo.DnsHostName = Dns.GetHostName();//本机名
                vo.Name        = adapter.Name;
                vo.Description = adapter.Description;
                vo.Speed       = adapter.Speed;

                //macAddress
                if (adapter.GetPhysicalAddress() != null && adapter.GetPhysicalAddress().ToString().Length > 0)
                {
                    char[] mac = adapter.GetPhysicalAddress().ToString().ToCharArray();
                    vo.MacAddress = mac[0] + mac[1] + "-" + mac[2] + mac[3] + "-" + mac[4] + mac[5] + "-" + mac[6] + mac[7] + "-" + mac[8] + mac[9] + "-" + mac[10] + mac[11];
                }

                //ipAddress subnetMask
                if (property.UnicastAddresses != null && property.UnicastAddresses.Count > 0)
                {
                    foreach (UnicastIPAddressInformation ip in property.UnicastAddresses)
                    {
                        if (ip.Address.AddressFamily.Equals(AddressFamily.InterNetwork))
                        {
                            if (ip.Address != null)
                            {
                                vo.Address = ip.Address.ToString();
                            }
                            if (ip.IPv4Mask != null)
                            {
                                vo.SubnetMask = ip.IPv4Mask.ToString();
                            }
                        }
                    }
                }

                // gateway
                if (property.GatewayAddresses != null && property.GatewayAddresses.Count > 0)
                {
                    foreach (GatewayIPAddressInformation uip in property.GatewayAddresses)
                    {
                        if (uip.Address.AddressFamily.Equals(AddressFamily.InterNetwork))
                        {
                            vo.Gateway = uip.Address.ToString();
                        }
                    }
                }

                // dns server
                if (property.DnsAddresses != null && property.DnsAddresses.Count > 0)
                {
                    vo.DnsServers = new List <string>();
                    foreach (IPAddress ip in property.DnsAddresses)
                    {
                        if (ip.AddressFamily.Equals(AddressFamily.InterNetwork))
                        {
                            vo.DnsServers.Add(ip.ToString());
                        }
                    }
                }

                // dhcp server
                if (property.DhcpServerAddresses != null && property.DhcpServerAddresses.Count > 0)
                {
                    foreach (IPAddress ip in property.DhcpServerAddresses)
                    {
                        if (ip.AddressFamily.Equals(AddressFamily.InterNetwork))
                        {
                            vo.DhcpServer  = ip.ToString();
                            vo.DhcpEnabled = true;
                        }
                    }
                }
                else
                {
                    vo.DhcpEnabled = false;
                }
                list.Add(vo);
            }
            return(list);
        }