导航菜单

页面标题

页面副标题

Mabilis Cash v1.19.4 - NetworkUtils.java 源代码

正在查看: Mabilis Cash v1.19.4 应用的 NetworkUtils.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.lingyue.supertoolkit.tools.phonetools;

import android.annotation.TargetApi;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import androidx.annotation.RequiresPermission;
import androidx.core.content.ContextCompat;
import com.lingyue.supertoolkit.tools.customtools.Logger;
import com.loans.mabiliscash.models.EasyCashDynamicTextInfo;
import com.qiniu.android.utils.Constants;
import cz.msebera.android.httpclient.conn.util.InetAddressUtils;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;
import org.json.JSONObject;

public class NetworkUtils {
    public static int a(Context context) {
        String e = e(context);
        if (TextUtils.isEmpty(e)) {
            return 0;
        }
        if (e.startsWith("46000") || e.startsWith("46002") || e.startsWith("46007")) {
            return 1;
        }
        if (e.startsWith("46001") || e.startsWith("46006")) {
            return 2;
        }
        return (e.startsWith("46003") || e.startsWith("46005") || e.startsWith("46011")) ? 3 : 0;
    }

    public static String b(Context context) {
        if (Build.VERSION.SDK_INT > 28) {
            return "UNAUTHORIZED";
        }
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
        if (telephonyManager == null) {
            return EasyCashDynamicTextInfo.TYPE_UNKNOWN;
        }
        try {
            String subscriberId = telephonyManager.getSubscriberId();
            if (TextUtils.isEmpty(subscriberId)) {
                return "NONE";
            }
            String str = (subscriberId.startsWith("46000") || subscriberId.startsWith("46002") || subscriberId.startsWith("46007") || subscriberId.startsWith("46020")) ? "中国移动" : (subscriberId.startsWith("46001") || subscriberId.startsWith("46006")) ? "中国联通" : (subscriberId.startsWith("46003") || subscriberId.startsWith("46005") || subscriberId.startsWith("46011")) ? "中国电信" : "其他 CELL";
            if ("其他 CELL".equals(str)) {
                return str;
            }
            return str + q(telephonyManager.getNetworkType());
        } catch (SecurityException e) {
            e.printStackTrace();
            return "UNAUTHORIZED";
        }
    }

    public static JSONObject c(Context context) {
        String str;
        String str2;
        String str3;
        if (ContextCompat.checkSelfPermission(context.getApplicationContext(), "android.permission.ACCESS_COARSE_LOCATION") != 0) {
            return null;
        }
        try {
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
            int a = a(context);
            if (a == 0) {
                return null;
            }
            String str4 = "";
            if (a == 1 || a == 2) {
                GsmCellLocation gsmCellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
                str = gsmCellLocation.getLac() + "";
                str2 = gsmCellLocation.getCid() + "";
            } else {
                if (a != 3) {
                    str3 = "";
                    int parseInt = Integer.parseInt(telephonyManager.getNetworkOperator().substring(3));
                    JSONObject jSONObject = new JSONObject();
                    jSONObject.put("mnc", parseInt);
                    jSONObject.put("lac", str4);
                    jSONObject.put("cid", str3);
                    jSONObject.put("type", p(context));
                    return jSONObject;
                }
                CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) telephonyManager.getCellLocation();
                str = cdmaCellLocation.getNetworkId() + "";
                str2 = cdmaCellLocation.getBaseStationId() + "";
            }
            str3 = str2;
            str4 = str;
            int parseInt2 = Integer.parseInt(telephonyManager.getNetworkOperator().substring(3));
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("mnc", parseInt2);
            jSONObject2.put("lac", str4);
            jSONObject2.put("cid", str3);
            jSONObject2.put("type", p(context));
            return jSONObject2;
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    public static String d(Context context) {
        try {
            WifiManager wifiManager = (WifiManager) context.getSystemService(Constants.NETWORK_WIFI);
            if (wifiManager == null) {
                return null;
            }
            DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();
            return u(dhcpInfo.dns1) + "," + u(dhcpInfo.dns2);
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    public static String e(Context context) {
        if (Build.VERSION.SDK_INT >= 29) {
            return "";
        }
        try {
            String subscriberId = ((TelephonyManager) context.getSystemService("phone")).getSubscriberId();
            return subscriberId == null ? "" : subscriberId;
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String f(Context context) {
        try {
            int ipAddress = ((WifiManager) context.getSystemService(Constants.NETWORK_WIFI)).getConnectionInfo().getIpAddress();
            if (ipAddress != 0) {
                Logger c = Logger.c();
                StringBuilder sb = new StringBuilder();
                sb.append("WIFI network, IP=");
                long j = ipAddress;
                sb.append(u(j));
                c.a(sb.toString());
                return u(j);
            }
        } catch (Exception | NoClassDefFoundError unused) {
            Logger.c().e("当前不在 WIFI 环境");
        }
        try {
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            while (networkInterfaces.hasMoreElements()) {
                Enumeration<InetAddress> inetAddresses = networkInterfaces.nextElement().getInetAddresses();
                while (inetAddresses.hasMoreElements()) {
                    InetAddress nextElement = inetAddresses.nextElement();
                    if (!nextElement.isLoopbackAddress() && InetAddressUtils.isIPv4Address(nextElement.getHostAddress().toUpperCase())) {
                        Logger.c().a("Cellphone network IPv4=" + nextElement.getHostAddress());
                        return nextElement.getHostAddress();
                    }
                }
            }
        } catch (SocketException unused2) {
            Logger.c().b("未获取到当前设备移动网络IP");
        }
        Logger.c().h("未获取到当前设备ip");
        return "127.0.0.1";
    }

    public static String g(Context context) {
        int i = Build.VERSION.SDK_INT;
        return i > 28 ? "" : i >= 23 ? h() : i(context);
    }

    @TargetApi(23)
    private static String h() {
        try {
            for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
                if (networkInterface.getName().equalsIgnoreCase("wlan0")) {
                    byte[] hardwareAddress = networkInterface.getHardwareAddress();
                    if (hardwareAddress == null) {
                        return "";
                    }
                    StringBuilder sb = new StringBuilder();
                    for (byte b : hardwareAddress) {
                        sb.append(Integer.toHexString(b & 255));
                        sb.append(":");
                    }
                    if (sb.length() > 0) {
                        sb.deleteCharAt(sb.length() - 1);
                    }
                    return sb.toString();
                }
            }
            return "02:00:00:00:00:00";
        } catch (Exception e) {
            Logger.c().b(e.toString());
            return "02:00:00:00:00:00";
        }
    }

    private static String i(Context context) {
        try {
            WifiInfo connectionInfo = ((WifiManager) context.getSystemService(Constants.NETWORK_WIFI)).getConnectionInfo();
            return connectionInfo.getMacAddress() != null ? connectionInfo.getMacAddress() : "";
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String j(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        if (connectivityManager == null) {
            return EasyCashDynamicTextInfo.TYPE_UNKNOWN;
        }
        try {
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) {
                return "NONE";
            }
            int type = activeNetworkInfo.getType();
            return type != 0 ? type != 1 ? EasyCashDynamicTextInfo.TYPE_UNKNOWN : "WIFI" : q(activeNetworkInfo.getSubtype());
        } catch (Exception unused) {
            return "UNAUTHORIZED";
        }
    }

    private static String k(int i) {
        switch (i) {
            case 1:
                return "GPRS";
            case 2:
                return "EDGE";
            case 3:
                return "UMTS";
            case 4:
                return "CDMA";
            case 5:
                return "CDMA - EvDo rev. 0";
            case 6:
                return "CDMA - EvDo rev. A";
            case 7:
                return "CDMA - 1xRTT";
            case 8:
                return "HSDPA";
            case 9:
                return "HSUPA";
            case 10:
                return "HSPA";
            case 11:
                return "iDEN";
            case 12:
                return "CDMA - EvDo rev. B";
            case 13:
                return "LTE";
            case 14:
                return "CDMA - eHRPD";
            case 15:
                return "HSPA+";
            case 16:
                return "GSM";
            case 17:
                return "TD_SCDMA";
            case 18:
                return "IWLAN";
            default:
                return EasyCashDynamicTextInfo.TYPE_UNKNOWN;
        }
    }

    public static String l(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        if (connectivityManager != null) {
            try {
                NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
                if (activeNetworkInfo != null) {
                    int type = activeNetworkInfo.getType();
                    if (type == 0) {
                        return k(activeNetworkInfo.getSubtype());
                    }
                    if (type == 1) {
                        return "WIFI";
                    }
                }
            } catch (Exception unused) {
                return "UNAUTHORIZED";
            }
        }
        return k(0);
    }

    public static String m(Context context) {
        String networkOperatorName = ((TelephonyManager) context.getSystemService("phone")).getNetworkOperatorName();
        return networkOperatorName == null ? "" : networkOperatorName;
    }

    public static String n(Context context) {
        try {
            int phoneType = ((TelephonyManager) context.getSystemService("phone")).getPhoneType();
            return phoneType != 1 ? phoneType != 2 ? phoneType != 3 ? "NONE" : "SIP" : "CDMA" : "GSM";
        } catch (Throwable unused) {
            return "NONE";
        }
    }

    public static String o(Context context) {
        try {
            return System.getProperty("http.proxyHost") + ":" + System.getProperty("http.proxyPort");
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    public static String p(Context context) {
        try {
            return k(((TelephonyManager) context.getSystemService("phone")).getNetworkType());
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    private static String q(int i) {
        if (i == 20) {
            return "5G";
        }
        switch (i) {
            case 1:
            case 2:
            case 4:
            case 7:
            case 11:
            case 16:
                return "2G";
            case 3:
            case 5:
            case 6:
            case 8:
            case 9:
            case 10:
            case 12:
            case 14:
            case 15:
            case 17:
                return "3G";
            case 13:
                return "4G";
            default:
                return EasyCashDynamicTextInfo.TYPE_UNKNOWN;
        }
    }

    @RequiresPermission("android.permission.ACCESS_WIFI_STATE")
    public static WifiInfo r(Context context) {
        try {
            WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Constants.NETWORK_WIFI);
            if (wifiManager != null) {
                return wifiManager.getConnectionInfo();
            }
            return null;
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    @RequiresPermission("android.permission.ACCESS_WIFI_STATE")
    public static String s(Context context) {
        try {
            return u(((WifiManager) context.getSystemService(Constants.NETWORK_WIFI)).getDhcpInfo().netmask);
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    @RequiresPermission("android.permission.ACCESS_WIFI_STATE")
    public static String t(Context context) {
        try {
            return u(((WifiManager) context.getSystemService(Constants.NETWORK_WIFI)).getDhcpInfo().gateway);
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    public static String u(long j) {
        return (j & 255) + "." + ((j >> 8) & 255) + "." + ((j >> 16) & 255) + "." + ((j >> 24) & 255);
    }

    public static boolean v(Context context) {
        try {
            return ((ConnectivityManager) context.getSystemService("connectivity")).getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED;
        } catch (Throwable th) {
            th.printStackTrace();
            return false;
        }
    }
}