我正在尝试使用以下代码获取Linux系统的MAC地址:
但它总是崩溃...有人知道为什么吗?
try {
ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
// System.out.print("Current MAC address: ");
for (int i = 0; i < mac.length; i++) {
is = is + Integer.parseInt(
String.format("%02X%s", mac[i], (i < mac.length - 1) ? "" : ""),16);
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
}
但它总是崩溃...有人知道为什么吗?