网站管理员要干些什么,南京网站设计建设,软件销售,wordpress主菜单设置以前#xff0c;为了获取MAC地址#xff0c;我们需要使用本机代码作为解决方案。在JDK 1.6中#xff0c;java.net.NetworkInterface类中添加了一个新方法#xff0c;该方法为getHardwareAddress()。package org.nhooo.example.network;import java.net.InetAddress;import …以前为了获取MAC地址我们需要使用本机代码作为解决方案。在JDK 1.6中java.net.NetworkInterface类中添加了一个新方法该方法为getHardwareAddress()。package org.nhooo.example.network;import java.net.InetAddress;import java.net.NetworkInterface;import java.net.SocketException;import java.net.UnknownHostException;public class MacAddress {public static void main(String[] args) {try {// InetAddress地址 InetAddress.getLocalHost();InetAddress address InetAddress.getByName(192.168.42.26);/** 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 hexadecimal with the following format* 08-00-27-DC-4A-9E.*/for (int i 0; i System.out.format(%02X%s,mac[i], (i }} else {System.out.println(Address doesnt exist or is not accessible.);}} else {System.out.println(Network Interface for the specified address is not found.);}} catch (UnknownHostException | SocketException e) {e.printStackTrace();}}}