0

I have an Android app to which I am trying to add DNS SRV record detection. I know it is possible, based on the existence of apps such as DNS Lookup, which I have installed, and it works just fine.

I am using dnsjava and this code runs fine as a stand-alone Java application on my machine, but when I run it on my Android device, I just get the "Error!" message:

Lookup lookup = new Lookup(serviceName, Type.SRV, DClass.IN);
Resolver resolver = new SimpleResolver();
lookup.setResolver(resolver);
lookup.setCache(null);
Record[] records = lookup.run();
if (lookup.getResult() == Lookup.SUCCESSFUL) {
    String responseMessage = null;
    String listingType = null;
    for (int i=0; i < records.length; i++) {
        if (records[i] instanceof SRVRecord) {
            listingType = ((SRVRecord) records[i]).toString()
        }
    }

    System.out.println("Found!");
    System.out.println("Response Message: "+responseMessage);
    System.out.println("Listing type: "+listingType);
} else if (lookup.getResult() == Lookup.HOST_NOT_FOUND) {
    System.out.println("Not found.");
} else {
    System.out.println("Error!");
}

Any ideas why this isn't working?

Big-O Claire
  • 956
  • 8
  • 13

2 Answers2

1

Using a very different setup for SRV lookup in Android; I found they always failed with a 'not found', unless I add the following to my Android Manifest:

<uses-permission android:name="android.permission.INTERNET" />
TinkerTank
  • 5,685
  • 2
  • 32
  • 41
0

I am not allowed to comment -- otherwise I would.

Make more else if statements, for example:

else if (lookup.getResult() == Lookup.HOST_NOT_FOUND) {
                    System.out.println("Not found.");
                } else if (lookup.getResult() == Lookup.TRY_AGAIN) {
                    System.out.println("Error!1");
                }  else if (lookup.getResult() == Lookup.TYPE_NOT_FOUND) {
                    System.out.println("Error!2");
                } else if (lookup.getResult() == Lookup.UNRECOVERABLE) {
                    System.out.println("Error!3");
                }

Also, try changing: DClass.IN to DClass.ANY

SeaRoth
  • 177
  • 5
  • 17