BF2Statistics.Net.Networking.GetIpAddress C# (CSharp) Method

GetIpAddress() public static method

Takes a domain name, or IP address, and returns the Correct IP address. If multiple IP addresses are found, the first one is returned
public static GetIpAddress ( string text ) : IPAddress
text string Domain name or IP Address
return System.Net.IPAddress
        public static IPAddress GetIpAddress(string text)
        {
            // Make sure the IP address is valid!
            IPAddress Address;
            bool isValid = IPAddress.TryParse(text, out Address);

            // If the IP address is invalid, try to parse as domain name
            if (!isValid)
            {
                // Try to get dns value
                IPAddress[] Addresses;
                try {
                    Addresses = Dns.GetHostAddresses(text);
                }
                catch {
                    throw new Exception("Invalid Hostname or IP Address");
                }

                if (Addresses.Length == 0)
                    throw new Exception("Invalid Hostname or IP Address");

                // Return first address
                return Addresses[0];
            }

            return Address;
        }