java自动获取电脑ip和MAC地址
InetAddress ip = InetAddress.getLocalHost(); System.out.println("IP:"+ip); NetworkInterface network = NetworkInterface.getByInetAddress(ip); byte[] mac = network.getHardwareAddress(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); } String hostMac=sb.toString(); System.out.println("Current MAC address : "+hostMac);