同程有借 v1.0.0版本的 MD5 值为:e33397cdbab33543d0c134ec96d77fb8

以下内容为反编译后的 n.java 源代码,内容仅作参考


package com.bonree.sdk.bz;

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.List;
import java.util.Set;
public final class n {
    private static final String f5667a = "DnsServersDetector";
    private static final String[] f5668b = {"8.8.8.8", "8.8.4.4"};
    private static final String f5669c = "]: [";
    private Context f5670d;

    private n(Context context) {
        this.f5670d = context;
    }

    private String[] a() {
        String[] c9 = c();
        if (c9 == null || c9.length <= 0) {
            String[] b9 = b();
            if (b9 == null || b9.length <= 0) {
                String[] d9 = d();
                return (d9 == null || d9.length <= 0) ? f5668b : d9;
            }
            return b9;
        }
        return c9;
    }

    private String[] b() {
        Network[] allNetworks;
        if (Build.VERSION.SDK_INT >= 21) {
            try {
                ArrayList arrayList = new ArrayList();
                ArrayList arrayList2 = new ArrayList();
                ConnectivityManager connectivityManager = (ConnectivityManager) this.f5670d.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 (a(linkProperties)) {
                                for (InetAddress inetAddress : dnsServers) {
                                    arrayList.add(inetAddress.getHostAddress());
                                }
                            } else {
                                for (InetAddress inetAddress2 : dnsServers) {
                                    arrayList2.add(inetAddress2.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;
            }
        }
        return null;
    }

    private static String[] c() {
        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 i9 = 0; i9 < 4; i9++) {
                    String str = (String) method.invoke(null, strArr[i9]);
                    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;
    }

    private String[] d() {
        if (Build.VERSION.SDK_INT >= 16) {
            try {
                Set<String> a9 = a(new LineNumberReader(new InputStreamReader(Runtime.getRuntime().exec("getprop").getInputStream())));
                if (a9.size() > 0) {
                    return (String[]) a9.toArray(new String[0]);
                }
                return null;
            } catch (Exception unused) {
                return null;
            }
        }
        return null;
    }

    private static Set<String> a(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(f5669c);
            if (indexOf != -1) {
                String substring = readLine.substring(1, indexOf);
                int i9 = indexOf + 4;
                int length = readLine.length() - 1;
                if (length >= i9) {
                    String substring2 = readLine.substring(i9, 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);
                        }
                    }
                }
            }
        }
    }

    @TargetApi(21)
    private static boolean a(LinkProperties linkProperties) {
        for (RouteInfo routeInfo : linkProperties.getRoutes()) {
            if (routeInfo.isDefaultRoute()) {
                return true;
            }
        }
        return false;
    }
}