正在查看: 95爱播免登录版 v3.1.9 应用的 DnsServersDetector.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 95爱播免登录版 v3.1.9 应用的 DnsServersDetector.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.netease.LDNetDiagnoService;
import android.annotation.TargetApi;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.RouteInfo;
import android.os.Build;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class DnsServersDetector {
private static final String[] FACTORY_DNS_SERVERS = {"8.8.8.8", "8.8.4.4"};
private static final String METHOD_EXEC_PROP_DELIM = "]: [";
private static final String TAG = "DnsServersDetector";
private Context context;
public DnsServersDetector(Context context) {
this.context = context;
}
private String[] getServersMethodConnectivityManager() {
if (Build.VERSION.SDK_INT < 21) {
return null;
}
try {
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
ConnectivityManager connectivityManager = (ConnectivityManager) this.context.getSystemService("connectivity");
if (connectivityManager != null) {
for (Network network : connectivityManager.getAllNetworks()) {
if (connectivityManager.getNetworkInfo(network).isConnected()) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
List<InetAddress> dnsServers = linkProperties.getDnsServers();
if (linkPropertiesHasDefaultRoute(linkProperties)) {
Iterator<InetAddress> it = dnsServers.iterator();
while (it.hasNext()) {
arrayList.add(it.next().getHostAddress());
}
} else {
Iterator<InetAddress> it2 = dnsServers.iterator();
while (it2.hasNext()) {
arrayList2.add(it2.next().getHostAddress());
}
}
}
}
}
if (arrayList.isEmpty()) {
arrayList.addAll(arrayList2);
}
if (arrayList.size() > 0) {
return (String[]) arrayList.toArray(new String[0]);
}
return null;
} catch (Exception unused) {
return null;
}
}
private String[] getServersMethodExec() {
if (Build.VERSION.SDK_INT < 16) {
return null;
}
try {
Set<String> methodExecParseProps = methodExecParseProps(new LineNumberReader(new InputStreamReader(Runtime.getRuntime().exec("getprop").getInputStream())));
if (methodExecParseProps == null || methodExecParseProps.size() <= 0) {
return null;
}
return (String[]) methodExecParseProps.toArray(new String[0]);
} catch (Exception unused) {
return null;
}
}
private String[] getServersMethodSystemProperties() {
if (Build.VERSION.SDK_INT < 26) {
ArrayList arrayList = new ArrayList();
try {
Method method = Class.forName("android.os.SystemProperties").getMethod("get", String.class);
String[] strArr = {"net.dns1", "net.dns2", "net.dns3", "net.dns4"};
for (int i2 = 0; i2 < 4; i2++) {
String str = (String) method.invoke(null, strArr[i2]);
if (str != null && ((str.matches("^\\d+(\\.\\d+){3}$") || str.matches("^[0-9a-f]+(:[0-9a-f]*)+:[0-9a-f]+$")) && !arrayList.contains(str))) {
arrayList.add(str);
}
}
if (arrayList.size() > 0) {
return (String[]) arrayList.toArray(new String[0]);
}
} catch (Exception unused) {
}
}
return null;
}
@TargetApi(21)
private boolean linkPropertiesHasDefaultRoute(LinkProperties linkProperties) {
Iterator<RouteInfo> it = linkProperties.getRoutes().iterator();
while (it.hasNext()) {
if (it.next().isDefaultRoute()) {
return true;
}
}
return false;
}
private Set<String> methodExecParseProps(BufferedReader bufferedReader) throws Exception {
String hostAddress;
HashSet hashSet = new HashSet(10);
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
return hashSet;
}
int indexOf = readLine.indexOf(METHOD_EXEC_PROP_DELIM);
if (indexOf != -1) {
String substring = readLine.substring(1, indexOf);
int i2 = indexOf + 4;
int length = readLine.length() - 1;
if (length < i2) {
String str = "Malformed property detected: \"" + readLine + '\"';
} else {
String substring2 = readLine.substring(i2, length);
if (!substring2.isEmpty() && (substring.endsWith(".dns") || substring.endsWith(".dns1") || substring.endsWith(".dns2") || substring.endsWith(".dns3") || substring.endsWith(".dns4"))) {
InetAddress byName = InetAddress.getByName(substring2);
if (byName != null && (hostAddress = byName.getHostAddress()) != null && hostAddress.length() != 0) {
hashSet.add(hostAddress);
}
}
}
}
}
}
public String[] getServers() {
String[] serversMethodSystemProperties = getServersMethodSystemProperties();
if (serversMethodSystemProperties != null && serversMethodSystemProperties.length > 0) {
return serversMethodSystemProperties;
}
String[] serversMethodConnectivityManager = getServersMethodConnectivityManager();
if (serversMethodConnectivityManager != null && serversMethodConnectivityManager.length > 0) {
return serversMethodConnectivityManager;
}
String[] serversMethodExec = getServersMethodExec();
return (serversMethodExec == null || serversMethodExec.length <= 0) ? FACTORY_DNS_SERVERS : serversMethodExec;
}
}