All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eleme.openapi.sdk.utils.ClientEnvUtils Maven / Gradle / Ivy

There is a newer version: 1.30.71
Show newest version
package eleme.openapi.sdk.utils;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.InetAddress;
import java.net.NetworkInterface;

public class ClientEnvUtils {
    /**
     * 获取本机mac地址
     *
     * @return String 本机mac地址
     */
    public static String getLocalMac() {
        try {
            byte[] mac = NetworkInterface.getByInetAddress(InetAddress.getLocalHost()).getHardwareAddress();
            StringBuffer sb = new StringBuffer("");
            for (int i = 0; i < mac.length; i++) {
                if (i != 0) {
                    sb.append("-");
                }
                int temp = mac[i] & 0xff;
                String str = Integer.toHexString(temp);
                if (str.length() == 1) {
                    sb.append("0" + str);
                } else {
                    sb.append(str);
                }
            }
            return sb.toString().toUpperCase();
        } catch (Exception e) {

        }
        return "UNKONOW_MAC";
    }

    /**
     * 获取本机进程ID
     *
     * @return String 本机进程ID
     */
    public static final int getProcessID() {
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        System.out.println(runtimeMXBean.getName());
        return Integer.valueOf(runtimeMXBean.getName().split("@")[0])
            .intValue();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy