Example #1
0
 public static IPAddress[] GetComputerIPs(IPAddressSelectType selectionType)
 {
     List<IPAddress> ips = new List<IPAddress>();
     try
     {
         String strHostName = Dns.GetHostName();
         IPHostEntry iphostentry = Dns.GetHostEntry(strHostName);
         foreach (IPAddress ipaddress in iphostentry.AddressList)
         {
             if (selectionType == IPAddressSelectType.ALL)
                 ips.Add(ipaddress);
             else if (selectionType == IPAddressSelectType.IPv4)
             {
                 if (ipaddress.ToString().Split('.').Length == 4)
                     ips.Add(ipaddress);
             }
             else if (selectionType == IPAddressSelectType.IPv6)
             {
                 if (ipaddress.ToString().Split('.').Length != 4)
                     ips.Add(ipaddress);
             }
         }
     }
     catch
     { }
     return ips.ToArray();
 }
Example #2
0
        public static IPAddress[] GetComputerIPs(IPAddressSelectType selectionType)
        {
            List <IPAddress> ips = new List <IPAddress>();

            try
            {
                String      strHostName = Dns.GetHostName();
                IPHostEntry iphostentry = Dns.GetHostEntry(strHostName);
                foreach (IPAddress ipaddress in iphostentry.AddressList)
                {
                    if (selectionType == IPAddressSelectType.ALL)
                    {
                        ips.Add(ipaddress);
                    }
                    else if (selectionType == IPAddressSelectType.IPv4)
                    {
                        if (ipaddress.ToString().Split('.').Length == 4)
                        {
                            ips.Add(ipaddress);
                        }
                    }
                    else if (selectionType == IPAddressSelectType.IPv6)
                    {
                        if (ipaddress.ToString().Split('.').Length != 4)
                        {
                            ips.Add(ipaddress);
                        }
                    }
                }
            }
            catch
            { }
            return(ips.ToArray());
        }