This project is read-only.

How to do a Reverse Name Lookup (PTR)

A Reverse name lookup takes an IP address and resolves it to a DNS Name. This is called a PTR (pointer) record.

Example Code
string dnsServer = "192.168.0.1";
string domainToResolve = "72.14.253.83";

DnsQueryRequest request = new DnsQueryRequest();
DnsQueryResponse response = request.Resolve(dnsServer, domainToResolve, NsType.PTR, NsClass.INET, ProtocolType.Udp);

Console.WriteLine("Bytes received: " + response.BytesReceived);

// Enumerate the Answer Records
Console.WriteLine("Answers:");
foreach (IDnsRecord record in response.Answers)
{
    Console.WriteLine(record.Answer);
    // Common IDnsRecord Fields
    Console.WriteLine("  |--- RDATA Field Length: " + record.DnsHeader.DataLength);
    Console.WriteLine("  |--- Name: " + record.DnsHeader.Name);
    Console.WriteLine("  |--- NS Class: " + record.DnsHeader.NsClass);
    Console.WriteLine("  |--- NS Type: " + record.DnsHeader.NsType);
    Console.WriteLine("  |--- TTL: " + record.DnsHeader.TimeToLive);
    Console.WriteLine();
}


Output
Bytes received: 77
Answers:
po-in-f83.google.com.
  |--- RDATA Field Length: 22
  |--- Name: 83.253.14.72.in-addr.arpa.
  |--- NS Class: INET
  |--- NS Type: PTR
  |--- TTL: 14800

Last edited Feb 5, 2008 at 3:10 PM by jmonty, version 2

Comments

No comments yet.