zoukankan      html  css  js  c++  java
  • java取得网卡地址

    String macStr = "";//MAC网卡地址
    try {
        InetAddress address = InetAddress.getLocalHost();//取得本地Ip地址
        System.out.println("getLocalHost:" + address.toString());
        //InetAddress address = InetAddress.getByName("192.168.46.53");
        NetworkInterface ni = NetworkInterface.getByInetAddress(address);
        if (ni != null) {
            byte[] mac = ni.getHardwareAddress();
            if (mac != null) {
                for (int i = 0; i < mac.length; i++) {
                    System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
                    macStr = macStr + String.format("%02X%s",mac[i],(i < mac.length - 1) ? "-" : "");//格式化输出
                }
            } else {
                System.out.println("Address doesn't exist or is not accessible.");
            }
        } else {
            System.out.println("Network Interface for the specified address is not found.");
    }
    } catch (UnknownHostException ex) {
        ex.printStackTrace();
    } catch (SocketException ex1) {
        ex1.printStackTrace();
    }
    System.out.println("macStr:" + macStr);
  • 相关阅读:
    sql语句的优化分析
    log4net.config
    redis lua 脚本实例
    Lua 脚本
    ServiceStack.Redis之IRedisClient<第三篇>
    有关Redis的Add和Set方法的比较
    如何在自己网站加上视频直播功能(搭建视频直播网站)
    带进度条的上传插件
    YII获取当前URL
    MYSQL常用命令
  • 原文地址:https://www.cnblogs.com/liuzhengdao/p/1918696.html
Copyright © 2011-2022 走看看