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

Query() public method

Queries server with specified query.
public Query ( string queryText, QTYPE queryType ) : DnsServerResponse
queryText string Query text. It depends on queryType.
queryType QTYPE Query type.
return DnsServerResponse
        public DnsServerResponse Query(string queryText,QTYPE queryType)
        {
            if(queryType == QTYPE.PTR){
                string ip = queryText;

                // See if IP is ok.
                IPAddress ipA = IPAddress.Parse(ip);
                queryText = "";

                // IPv6
                if(ipA.AddressFamily == AddressFamily.InterNetworkV6){
                    // 4321:0:1:2:3:4:567:89ab
                    // would be
                    // b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.ARPA

                    char[] ipChars = ip.Replace(":","").ToCharArray();
                    for(int i=ipChars.Length - 1;i>-1;i--){
                        queryText += ipChars[i] + ".";
                    }
                    queryText += "IP6.ARPA";
                }
                // IPv4
                else{
                    // 213.35.221.186
                    // would be
                    // 186.221.35.213.in-addr.arpa

                    string[] ipParts = ip.Split('.');
                    //--- Reverse IP ----------
                    for(int i=3;i>-1;i--){
                        queryText += ipParts[i] + ".";
                    }
                    queryText += "in-addr.arpa";
                }
            }

            return QueryServer(queryText,queryType,1);
        }

Usage Example

Example #1
0
//-------------------------------------------------------------------------------------------
    private string LookupA(string recordname, string sectiontext)
    {
        Dns_Client        dc  = new LumiSoft.Net.Dns.Client.Dns_Client();
        DnsServerResponse dsr = null;

        try
        {
            dsr = dc.Query(recordname, LumiSoft.Net.Dns.Client.QTYPE.A);
        }
        catch (Exception ex)
        {
            throw new Exception("DNS A record query for " + recordname + " failed.", ex);
        }
        DNS_rr_A[] records = dsr.GetARecords();

        string response = sectiontext;

        if (records.Length < 1)
        {
            fail = true;
        }
        for (int i = 0; i < records.Length; i++)
        {
            response += (i + 1) + ".&nbsp;&nbsp;&nbsp;";
            response += records[i].IP + " with a TTL of " + records[i].TTL + "<br>";
            response += CheckPort(records[i].IP.ToString(), 5222);
            response += CheckPort(records[i].IP.ToString(), 5223);
            response += CheckPort(records[i].IP.ToString(), 5269);
            response += CheckPort(records[i].IP.ToString(), 5270);
        }
        return(response);
    }
All Usage Examples Of LumiSoft.Net.Dns.Client.Dns_Client::Query