0

Ubuntu デバイスの MAC アドレスを抽出する次のコードがあり、MAC アドレスをデータベースに入れています。このコードは、Windows PC では正常に動作しますが、Ubuntu Device では同じように動作しません。データベース フィールドが空になります。私のアプリケーションは Web アプリケーションです。私はwarファイルを取得し、それをUbuntuデバイスにあるTomcatサーバーに入れています。

 public static String getMACAddress()
  {
    StringBuffer strMac = new StringBuffer();
    try {

        InetAddress address = InetAddress.getLocalHost();
        // InetAddress address = InetAddress.getByName("192.168.46.53");

        /*
         * Get NetworkInterface for the current host and then read the
         * hardware address.
         */
        NetworkInterface ni = NetworkInterface.getByInetAddress(address);
        if (ni != null) {
            byte[] mac = ni.getHardwareAddress();
            if (mac != null) {
                /*
                 * Extract each array of mac address and convert it to hexa
                 * with the following format 08-00-27-DC-4A-9E.
                 */
                for (int i = 0; i < mac.length; i++) {
                    System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
                    strMac.append(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 (Exception e) {

    }
    return strMac.toString();
         }

この( Java - Linux システムの MAC アドレスの取得) リンクも参照しました。

私のUbuntuデバイスは、LANとWifi接続の両方を使用しています。

私の質問が明確であることを願っています。助けてください...ありがとう

4

1 に答える 1