Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...