zoukankan      html  css  js  c++  java
  • Java 获取本机MAC地址

    package com.mobai.util;

    //实际使用时MAC地址差1

    import java.net.NetworkInterface;
    import java.net.SocketException;
    import java.util.Enumeration;

    public class GetMac {
    private static String hexByte(byte b) {
    String s = "000000" + Integer.toHexString(b);
    return s.substring(s.length() - 2);
    }

    public static String getHostMAC(String split) throws SocketException {
    Enumeration<NetworkInterface> networkInterface_enumeration;
    String mac_address = "";
    networkInterface_enumeration = NetworkInterface.getNetworkInterfaces();
    while (networkInterface_enumeration.hasMoreElements()) {
    byte[] mac = networkInterface_enumeration.nextElement().getHardwareAddress();
    if (mac == null)
    continue;
    mac_address = hexByte(mac[0]) + split + hexByte(mac[1]) + split
    + hexByte(mac[2]) + split + hexByte(mac[3]) + split
    + hexByte(mac[4]) + split + hexByte(mac[5]);
    }
    return mac_address;
    }
    }

  • 相关阅读:
    table表格
    常见页面布局方式(三种框架集)
    学习标签属性3
    学习标签属性2
    学习标签属性1
    Purity in My Programming: Functions in Go
    cron一有趣处
    go函数作为一等民
    LRU算法
    go中的一个网络重连复用
  • 原文地址:https://www.cnblogs.com/mobai95/p/13736218.html
Copyright © 2011-2022 走看看