Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

Android Resolve DNS SRV records

In my application, I am trying to resolve the SRV DNS records for a domain. Durinf my research, I stumbled upon Lightweight way to resolve DNS SRV records on Android and found dnsjava and minidns that have the capability of doing these.

1. dnsjava

Upon implementation I found that dnsjava is not able to resolve the records and the list is always null. The code that I used is:

private void dnsjava () {
    try {
        Lookup configLookup = new Lookup(URL, Type.SRV);
        //configLookup.setResolver(new ExtendedResolver());
        Record[] records = configLookup.run();
        if ( records != null && records.length > 0 ) {
            for ( Record record : records ) {
                SRVRecord srv = (SRVRecord) record;
                String hostname = srv.getTarget().toString();
                Log.d(TAG, "Hostname: " + hostname);
            }
        } else {
            Log.e(TAG, "NO record");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

But this always prints NO record.

2. minidns

BY usnig minidns I was able to get the SRC records, however it takes almost 2 minutes to resolve this. Such long wait time is almost unacceptable. The code I used is:

private void minidns () throws IOException {
    AndroidUsingLinkProperties.setup(getApplicationContext());

    SrvResolverResult res = ResolverApi.INSTANCE.resolveSrv(URL);

    if ( ! res.wasSuccessful() ) {
        Log.d(TAG, "Not successful");
    } else {
        List<SrvResolverResult.ResolvedSrvRecord> srvRecords = res.getSortedSrvResolvedAddresses();
        for ( SrvResolverResult.ResolvedSrvRecord srvRecord : srvRecords ) {
            Log.d(TAG, "Hostname: " + srvRecord.aRecordsResult.getQuestion().name.toString());
            for ( InternetAddressRR inetAddressRR : srvRecord.addresses ) {
                InetAddress inetAddress = inetAddressRR.getInetAddress();
                Log.d(TAG, "IP: " + inetAddress.getHostName());
            }
        }
    }
}

Here ResolverApi.INSTANCE.resolveSrv(URL) takes few seconds to return the result and res.getSortedSrvResolvedAddresses() takes almost 2 minutes to return.

So, my questions are:

  1. Is there a way to opmitize the minidns implementation? OR
  2. How can I make the dnsjava work? I am testing it on the latest version of Android. There are some issues starting with Android O but not sure how to get around that. OR
  3. Is there any other way to resolve the SRV records on Android?
question from:https://stackoverflow.com/questions/66053072/android-resolve-dns-srv-records

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...