From 9dbbc209a9810b337732d72c0da409c71f9b49ee Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 15 Apr 2020 21:25:44 +0200 Subject: [PATCH] Added simple DNS test --- app/src/main/java/eu/faircode/email/DNSHelper.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/DNSHelper.java b/app/src/main/java/eu/faircode/email/DNSHelper.java index 6c9b2848a3..cc322ec3a8 100644 --- a/app/src/main/java/eu/faircode/email/DNSHelper.java +++ b/app/src/main/java/eu/faircode/email/DNSHelper.java @@ -31,6 +31,7 @@ import androidx.annotation.NonNull; import org.xbill.DNS.Lookup; import org.xbill.DNS.MXRecord; import org.xbill.DNS.Record; +import org.xbill.DNS.SRVRecord; import org.xbill.DNS.SimpleResolver; import org.xbill.DNS.TextParseException; import org.xbill.DNS.Type; @@ -172,4 +173,17 @@ public class DNSHelper { else return dns.get(0).getHostAddress(); } + + static void test(Context context) { + try { + String domain = "gmail.com"; + boolean ok = lookupMx(context, new Address[]{Log.myAddress()}); + InetAddress iaddr = lookupMx(context, domain); + Record[] records = DNSHelper.lookup(context, "_imaps._tcp." + domain, Type.SRV); + SRVRecord srv = (SRVRecord) records[0]; + Log.i("DNS ok=" + ok + " iaddr=" + iaddr + " srv=" + srv.getTarget().toString()); + } catch (Throwable ex) { + Log.e("DNS", ex); + } + } }