4399游戏盒 v7.2.1.31版本的 MD5 值为:951717f45e3fda95c8a358caf4ca93e1

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


package com.framework.utils;

import android.text.TextUtils;
import com.m4399.gamecenter.plugin.main.manager.i.d;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Enumeration;
import timber.log.Timber;

public class NetUtils {
    public static String getHostIpAddress() {
        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()) {
                        return nextElement.getHostAddress();
                    }
                }
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static boolean isLocalPortInUse(int i) {
        try {
            return g("127.0.0.1", i);
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return false;
        }
    }

    private static boolean g(String str, int i) throws UnknownHostException {
        try {
            new Socket(InetAddress.getByName(str), i).close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }

    public static String getInetAddress(String str) {
        try {
            return InetAddress.getByName(str).getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String getInetAddressByUrl(String str) {
        try {
            if (!TextUtils.isEmpty(str)) {
                String[] split = str.replace(d.MIME_TYPE_HTTP, "").split("/");
                if (split.length >= 1) {
                    return getInetAddress(split[0]);
                }
            }
        } catch (Exception e) {
            Timber.d(e.getMessage(), new Object[0]);
        }
        return "";
    }
}