CryptoMessage v1.3.2版本的 MD5 值为:66c611ce56a11450659dc23697562928
以下内容为反编译后的 DnsClient.java 源代码,内容仅作参考
package org.minidns;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.minidns.AbstractDnsClient;
import org.minidns.MiniDnsException;
import org.minidns.dnsmessage.DnsMessage;
import org.minidns.dnsqueryresult.CachedDnsQueryResult;
import org.minidns.dnsqueryresult.DnsQueryResult;
import org.minidns.dnsserverlookup.AndroidUsingExec;
import org.minidns.dnsserverlookup.AndroidUsingReflection;
import org.minidns.dnsserverlookup.DnsServerLookupMechanism;
import org.minidns.dnsserverlookup.UnixUsingEtcResolvConf;
import org.minidns.util.CollectionsUtil;
import org.minidns.util.InetAddressUtil;
import org.minidns.util.MultipleIoException;
public class DnsClient extends AbstractDnsClient {
static final List<DnsServerLookupMechanism> LOOKUP_MECHANISMS = new CopyOnWriteArrayList();
static final Set<Inet4Address> STATIC_IPV4_DNS_SERVERS;
static final Set<Inet6Address> STATIC_IPV6_DNS_SERVERS;
private static final Set<String> blacklistedDnsServers;
private boolean askForDnssec;
private boolean disableResultFilter;
private final Set<InetAddress> nonRaServers;
private boolean useHardcodedDnsServers;
static {
CopyOnWriteArraySet copyOnWriteArraySet = new CopyOnWriteArraySet();
STATIC_IPV4_DNS_SERVERS = copyOnWriteArraySet;
STATIC_IPV6_DNS_SERVERS = new CopyOnWriteArraySet();
addDnsServerLookupMechanism(AndroidUsingExec.INSTANCE);
addDnsServerLookupMechanism(AndroidUsingReflection.INSTANCE);
addDnsServerLookupMechanism(UnixUsingEtcResolvConf.INSTANCE);
try {
copyOnWriteArraySet.add(InetAddressUtil.ipv4From("8.8.8.8"));
} catch (IllegalArgumentException e) {
AbstractDnsClient.LOGGER.log(Level.WARNING, "Could not add static IPv4 DNS Server", (Throwable) e);
}
try {
STATIC_IPV6_DNS_SERVERS.add(InetAddressUtil.ipv6From("[2001:4860:4860::8888]"));
} catch (IllegalArgumentException e2) {
AbstractDnsClient.LOGGER.log(Level.WARNING, "Could not add static IPv6 DNS Server", (Throwable) e2);
}
blacklistedDnsServers = Collections.newSetFromMap(new ConcurrentHashMap(4));
}
public DnsClient(DnsCache dnsCache) {
super(dnsCache);
this.nonRaServers = Collections.newSetFromMap(new ConcurrentHashMap(4));
this.askForDnssec = false;
this.disableResultFilter = false;
this.useHardcodedDnsServers = true;
}
@Override
public DnsMessage.Builder newQuestion(DnsMessage.Builder builder) {
builder.setRecursionDesired(true);
builder.getEdnsBuilder().setUdpPayloadSize(this.dataSource.getUdpPayloadSize()).setDnssecOk(this.askForDnssec);
return builder;
}
private List<InetAddress> getServerAddresses() {
InetAddress randomHardcodedIpv4DnsServer;
List<InetAddress> findDnsAddresses = findDnsAddresses();
if (this.useHardcodedDnsServers) {
InetAddress inetAddress = null;
int i = AnonymousClass1.$SwitchMap$org$minidns$AbstractDnsClient$IpVersionSetting[this.ipVersionSetting.ordinal()];
if (i == 1) {
randomHardcodedIpv4DnsServer = getRandomHardcodedIpv4DnsServer();
inetAddress = getRandomHarcodedIpv6DnsServer();
} else if (i == 2) {
randomHardcodedIpv4DnsServer = getRandomHarcodedIpv6DnsServer();
inetAddress = getRandomHardcodedIpv4DnsServer();
} else if (i == 3) {
randomHardcodedIpv4DnsServer = getRandomHardcodedIpv4DnsServer();
} else if (i == 4) {
randomHardcodedIpv4DnsServer = getRandomHarcodedIpv6DnsServer();
} else {
throw new AssertionError("Unknown ipVersionSetting: " + this.ipVersionSetting);
}
findDnsAddresses.add(randomHardcodedIpv4DnsServer);
if (inetAddress != null) {
findDnsAddresses.add(inetAddress);
}
}
return findDnsAddresses;
}
@Override
public DnsQueryResult query(DnsMessage.Builder builder) throws IOException {
int i;
DnsMessage build = newQuestion(builder).build();
DnsCache dnsCache = this.cache;
CachedDnsQueryResult cachedDnsQueryResult = dnsCache == null ? null : dnsCache.get(build);
if (cachedDnsQueryResult != null) {
return cachedDnsQueryResult;
}
List<InetAddress> serverAddresses = getServerAddresses();
ArrayList arrayList = new ArrayList(serverAddresses.size());
for (InetAddress inetAddress : serverAddresses) {
if (this.nonRaServers.contains(inetAddress)) {
AbstractDnsClient.LOGGER.finer("Skipping " + inetAddress + " because it was marked as \"recursion not available\"");
} else {
try {
DnsQueryResult query = query(build, inetAddress);
DnsMessage dnsMessage = query.response;
if (!dnsMessage.recursionAvailable) {
if (this.nonRaServers.add(inetAddress)) {
AbstractDnsClient.LOGGER.warning("The DNS server " + inetAddress + " returned a response without the \"recursion available\" (RA) flag set. This likely indicates a misconfiguration because the server is not suitable for DNS resolution");
}
} else {
if (this.disableResultFilter || (i = AnonymousClass1.$SwitchMap$org$minidns$dnsmessage$DnsMessage$RESPONSE_CODE[dnsMessage.responseCode.ordinal()]) == 1 || i == 2) {
return query;
}
String str = "Response from " + inetAddress + " asked for " + build.getQuestion() + " with error code: " + dnsMessage.responseCode + '.';
Logger logger = AbstractDnsClient.LOGGER;
if (!logger.isLoggable(Level.FINE)) {
str = str + "\n" + dnsMessage;
}
logger.warning(str);
arrayList.add(new MiniDnsException.ErrorResponseException(build, query));
}
} catch (IOException e) {
arrayList.add(e);
}
}
}
MultipleIoException.throwIfRequired(arrayList);
throw new MiniDnsException.NoQueryPossibleException(build);
}
public static class AnonymousClass1 {
static final int[] $SwitchMap$org$minidns$AbstractDnsClient$IpVersionSetting;
static final int[] $SwitchMap$org$minidns$dnsmessage$DnsMessage$RESPONSE_CODE;
static {
int[] iArr = new int[DnsMessage.RESPONSE_CODE.values().length];
$SwitchMap$org$minidns$dnsmessage$DnsMessage$RESPONSE_CODE = iArr;
try {
iArr[DnsMessage.RESPONSE_CODE.NO_ERROR.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$org$minidns$dnsmessage$DnsMessage$RESPONSE_CODE[DnsMessage.RESPONSE_CODE.NX_DOMAIN.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
int[] iArr2 = new int[AbstractDnsClient.IpVersionSetting.values().length];
$SwitchMap$org$minidns$AbstractDnsClient$IpVersionSetting = iArr2;
try {
iArr2[AbstractDnsClient.IpVersionSetting.v4v6.ordinal()] = 1;
} catch (NoSuchFieldError unused3) {
}
try {
$SwitchMap$org$minidns$AbstractDnsClient$IpVersionSetting[AbstractDnsClient.IpVersionSetting.v6v4.ordinal()] = 2;
} catch (NoSuchFieldError unused4) {
}
try {
$SwitchMap$org$minidns$AbstractDnsClient$IpVersionSetting[AbstractDnsClient.IpVersionSetting.v4only.ordinal()] = 3;
} catch (NoSuchFieldError unused5) {
}
try {
$SwitchMap$org$minidns$AbstractDnsClient$IpVersionSetting[AbstractDnsClient.IpVersionSetting.v6only.ordinal()] = 4;
} catch (NoSuchFieldError unused6) {
}
}
}
public static List<String> findDNS() {
List<String> list;
DnsServerLookupMechanism next;
Iterator<DnsServerLookupMechanism> it = LOOKUP_MECHANISMS.iterator();
loop0: while (true) {
list = null;
while (true) {
if (!it.hasNext()) {
break loop0;
}
next = it.next();
try {
list = next.getDnsServerAddresses();
} catch (SecurityException e) {
AbstractDnsClient.LOGGER.log(Level.WARNING, "Could not lookup DNS server", (Throwable) e);
}
if (list != null) {
break;
}
}
AbstractDnsClient.LOGGER.warning("The DNS server lookup mechanism '" + next.getName() + "' returned not a single valid IP address after sanitazion");
}
return list;
}
public static List<InetAddress> findDnsAddresses() {
InetAddress byName;
List<String> findDNS = findDNS();
if (findDNS == null) {
return new ArrayList();
}
AbstractDnsClient.IpVersionSetting ipVersionSetting = AbstractDnsClient.DEFAULT_IP_VERSION_SETTING;
ArrayList arrayList = ipVersionSetting.v4 ? new ArrayList(findDNS.size()) : null;
ArrayList arrayList2 = ipVersionSetting.v6 ? new ArrayList(findDNS.size()) : null;
int i = 0;
for (String str : findDNS) {
try {
byName = InetAddress.getByName(str);
} catch (UnknownHostException e) {
AbstractDnsClient.LOGGER.log(Level.SEVERE, "Could not transform '" + str + "' to InetAddress", (Throwable) e);
}
if (byName instanceof Inet4Address) {
if (ipVersionSetting.v4) {
arrayList.add((Inet4Address) byName);
}
} else if (byName instanceof Inet6Address) {
if (ipVersionSetting.v6) {
arrayList2.add((Inet6Address) byName);
}
} else {
throw new AssertionError("The address '" + byName + "' is neither of type Inet(4|6)Address");
}
i++;
}
ArrayList arrayList3 = new ArrayList(i);
int i2 = AnonymousClass1.$SwitchMap$org$minidns$AbstractDnsClient$IpVersionSetting[ipVersionSetting.ordinal()];
if (i2 == 1) {
arrayList3.addAll(arrayList);
arrayList3.addAll(arrayList2);
} else if (i2 == 2) {
arrayList3.addAll(arrayList2);
arrayList3.addAll(arrayList);
} else if (i2 == 3) {
arrayList3.addAll(arrayList);
} else if (i2 == 4) {
arrayList3.addAll(arrayList2);
}
return arrayList3;
}
public static void addDnsServerLookupMechanism(DnsServerLookupMechanism dnsServerLookupMechanism) {
if (!dnsServerLookupMechanism.isAvailable()) {
AbstractDnsClient.LOGGER.fine("Not adding " + dnsServerLookupMechanism.getName() + " as it is not available.");
return;
}
List<DnsServerLookupMechanism> list = LOOKUP_MECHANISMS;
synchronized (list) {
ArrayList arrayList = new ArrayList(list.size() + 1);
arrayList.addAll(list);
arrayList.add(dnsServerLookupMechanism);
Collections.sort(arrayList);
list.clear();
list.addAll(arrayList);
}
}
public InetAddress getRandomHardcodedIpv4DnsServer() {
return (InetAddress) CollectionsUtil.getRandomFrom(STATIC_IPV4_DNS_SERVERS, this.insecureRandom);
}
public InetAddress getRandomHarcodedIpv6DnsServer() {
return (InetAddress) CollectionsUtil.getRandomFrom(STATIC_IPV6_DNS_SERVERS, this.insecureRandom);
}
}