LumiSoft.Net.Dns.Client.Dns_Client.Resolve C# (CSharp) Method

Resolve() public static method

Resolves a DNS host name or IP to IPAddress[].
public static Resolve ( string hostName_IP ) : System.Net.IPAddress[]
hostName_IP string Host name or IP address.
return System.Net.IPAddress[]
        public static IPAddress[] Resolve(string hostName_IP)
        {
            // If hostName_IP is IP
            try{
                return new IPAddress[]{IPAddress.Parse(hostName_IP)};
            }
            catch{
            }

            // This is probably NetBios name
            if(hostName_IP.IndexOf(".") == -1){
                return System.Net.Dns.Resolve(hostName_IP).AddressList;
            }
            else{
                // hostName_IP must be host name, try to resolve it's IP
                Dns_Client dns = new Dns_Client();
                DnsServerResponse resp = dns.Query(hostName_IP,QTYPE.A);
                if(resp.ResponseCode == RCODE.NO_ERROR){
                    A_Record[] records = resp.GetARecords();
                    IPAddress[] retVal = new IPAddress[records.Length];
                    for(int i=0;i<records.Length;i++){
                        retVal[i] = IPAddress.Parse(records[i].IP);
                    }

                    return retVal;
                }
                else{
                    throw new Exception(resp.ResponseCode.ToString());
                }
            }
        }