کد: انتخاب همه
InetAddress ip = InetAddress.getLocalHost();
System.out.println("IP : " + ip.getHostAddress());
NetworkInterface networkInterface = NetworkInterface.getByInetAddress(ip);
byte[] mac = networkInterface.getHardwareAddress();
System.out.print("MAC : ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
System.out.println(sb.toString());