Reverse DNS lookup

333 views
Skip to first unread message

bpat...@gmail.com

unread,
Oct 6, 2015, 7:35:17 AM10/6/15
to Netty discussions
Hi, 

I am new to Netty and was trying out the DNSNameResolver class which provides the way to resolve the name in a non blocking way, it works just fine but we have slightly different use case where we want to do the reverse DNS lookup, I have briefly went through the code and did not find anything useful, will be grateful if someone can answer my questions as below,


1 Does netty supports rDNS lookup?
2. If so, does it support that in a batch mode? :)


Thanks,
Bhavik




이희승 (Trustin Lee)

unread,
Oct 6, 2015, 8:43:27 AM10/6/15
to ne...@googlegroups.com
Hi Bhavik,
 
I'm not sure what the batch mode is, but you can make any query that's allowed in DNS protocol via DnsNameResolver.query(). For example, DnsNameResolverTest contains a test case that performs an MX query. I don't think reverse lookup isn't any different.
 
HTH,
T
 
--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
 

Bhavik Patel

unread,
Nov 17, 2015, 4:24:45 PM11/17/15
to Netty discussions
Hi,

I am trying following code to do the reverse DNS lookup,

    public static void main(String[] args) throws InterruptedException, UnknownHostException, ExecutionException {
        final EventLoopGroup group = new NioEventLoopGroup(1);
        final DnsNameResolver resolver = new DnsNameResolver(
                group.next(), NioDatagramChannel.class, DnsServerAddresses.shuffled(SERVERS));

            resolver.query(new DnsQuestion("216.58.216.36",DnsType.PTR,DnsClass.IN)).get().toString();

        Thread.currentThread().sleep(510000);
    }
}

But upon running the above code it throws following UnknownHostException,

Exception in thread "main" java.util.concurrent.ExecutionException: java.net.UnknownHostException: failed to resolve DnsQuestion(name: 216.58.216.36, type: PTR, class: IN) after 2 attempts:
from /173.36.224.109:53: query timed out after 5000 milliseconds
from /173.36.224.109:53: query timed out after 5000 milliseconds


it would be great if some one can help.



Thanks,
Bhavik

Bhavik Patel

unread,
Nov 17, 2015, 4:25:11 PM11/17/15
to Netty discussions
Hi,

I am trying following code to do the reverse DNS lookup,

    public static void main(String[] args) throws InterruptedException, UnknownHostException, ExecutionException {
        final EventLoopGroup group = new NioEventLoopGroup(1);
        final DnsNameResolver resolver = new DnsNameResolver(
                group.next(), NioDatagramChannel.class, DnsServerAddresses.shuffled(SERVERS));

            resolver.query(new DnsQuestion("216.58.216.36",DnsType.PTR,DnsClass.IN)).get().toString();

        Thread.currentThread().sleep(510000);
    }
}

But upon running the above code it throws following UnknownHostException,

Exception in thread "main" java.util.concurrent.ExecutionException: java.net.UnknownHostException: failed to resolve DnsQuestion(name: 216.58.216.36, type: PTR, class: IN) after 2 attempts:
from /173.36.224.109:53: query timed out after 5000 milliseconds
from /173.36.224.109:53: query timed out after 5000 milliseconds


it would be great if some one can help.



Thanks,
Bhavik


On Tuesday, October 6, 2015 at 5:43:27 AM UTC-7, Trustin Lee wrote:

이희승 (Trustin Lee)

unread,
Dec 18, 2015, 9:11:17 PM12/18/15
to ne...@googlegroups.com
Sorry I'm late. I tried the following code, and it works without a problem:
 
        final EventLoopGroup group = new NioEventLoopGroup(1);
        final DnsNameResolver resolver = new DnsNameResolverBuilder(group.next())
                .channelType(NioDatagramChannel.class)
                .nameServerAddresses(DnsServerAddresses.defaultAddresses())
                .build();
 
        System.out.println(resolver.query(new DefaultDnsQuestion(
                "36.216.58.216.in-addr.arpa", DnsRecordType.PTR, DnsRecord.CLASS_IN)).get());
 
You need to reverse your IP address and append '.in-addr.arpa' to do a reverse lookup, just in case you didn't know.
Reply all
Reply to author
Forward
0 new messages