diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..aa899e4
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..15a15b2
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..4b661a5
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..d128cd0
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,286 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1556256144233
+
+
+ 1556256144233
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No facets are configured
+
+
+
+
+
+
+
+
+
+
+
+ Python 2.7 interpreter library
+
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+ robustdns
+
+
+
+
+
+
+
+
+
+
+
+
+ Maven: com.google.code.gson:gson:2.8.5
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..6fa8184
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,123 @@
+
+
+ 4.0.0
+
+ com.doodream
+ robust-dns
+ 1.0.0-SNAPSHOT
+ jar
+
+ 2.1.12
+ 1.16.6
+ 1.7.25
+ 2.8.5
+ maven_repository
+
+
+
+
+ Apache License, Version 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+ repo
+
+
+
+
+
+
+ ar.com.synergian
+ wagon-git
+ 0.3.1
+
+
+
+
+ src/main/resources
+ true
+
+
+ src/test/resources
+ true
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.21.0
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.6
+
+
+ maven-deploy-plugin
+ 2.8.1
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ package
+
+ single
+
+
+
+ jar-with-dependencies
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.6.1
+
+
+ 1.8
+
+
+
+
+
+
+ io.reactivex.rxjava2
+ rxjava
+ ${rxjava_version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok_version}
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4j_version}
+
+
+
+ dnsjava
+ dnsjava
+ 2.1.8
+
+
+ com.google.code.gson
+ gson
+ ${gson_version}
+
+
+
+ junit
+ junit
+ 4.8.1
+ test
+
+
+
\ No newline at end of file
diff --git a/robustdns.iml b/robustdns.iml
new file mode 100644
index 0000000..78b2cc5
--- /dev/null
+++ b/robustdns.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/src/main/java/com/doodream/robustdns/RobustDnsResolver.java b/src/main/java/com/doodream/robustdns/RobustDnsResolver.java
new file mode 100644
index 0000000..09701d4
--- /dev/null
+++ b/src/main/java/com/doodream/robustdns/RobustDnsResolver.java
@@ -0,0 +1,67 @@
+package com.doodream.robustdns;
+
+import io.reactivex.Observable;
+import io.reactivex.Single;
+import org.xbill.DNS.*;
+
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+
+public class RobustDnsResolver {
+
+ private static final String[] CREDIBLE_DNS_ADDRESS = {
+ "8.8.8.8",
+ "8.8.4.4",
+ "1.1.1.1",
+ "205.251.198.30"
+ };
+
+ private final ExtendedResolver resolver;
+
+
+ public RobustDnsResolver(String ...dnsUrls) throws UnknownHostException {
+ List urls = new ArrayList<>();
+ if(dnsUrls != null && dnsUrls.length > 0) {
+ urls.addAll(Arrays.asList(dnsUrls));
+ }
+ urls.addAll(Arrays.asList(CREDIBLE_DNS_ADDRESS));
+ String[] allDnsUrls = urls.toArray(new String[0]);
+ resolver = new ExtendedResolver(Observable.fromArray(allDnsUrls)
+ .map(dnsAddress -> new SimpleResolver(dnsAddress))
+ .toList()
+ .blockingGet()
+ .toArray(new Resolver[0]));
+ }
+
+ public RobustDnsResolver() throws UnknownHostException {
+ this(new String[0]);
+ }
+
+ public Single resolve(String name) throws IOException {
+ return Single.create(emitter -> {
+ final Record question = Record.newRecord(Name.concatenate(Name.fromString(name), Name.root), Type.A, DClass.IN, TTL.MAX_VALUE);
+ final Message query = Message.newQuery(question);
+ resolver.sendAsync(query, new ResolverListener() {
+ @Override
+ public void receiveMessage(Object o, Message message) {
+ Record[] records = message.getSectionArray(Section.ANSWER);
+ if(records != null || records.length > 0) {
+ emitter.onSuccess(records[0].rdataToString());
+ } else {
+ emitter.onError(new UnknownHostException(String.format(Locale.ENGLISH, "%s not found", name)));
+ }
+ }
+
+ @Override
+ public void handleException(Object o, Exception e) {
+ emitter.onError(e);
+ }
+ });
+ });
+
+ }
+}