Public static void getAllMacAdress () {Enumeration <NetworkInterface> netInterfaces = null; try {// obtain all network interfaces netInterfaces = NetworkInterface. getNetworkInterfaces (); while (netInterfaces. hasMoreElements () {System. out. println ("========================================== ========= "); string mac = ""; StringBuffer sb = new StringBuffer (); NetworkInterface ni = netInterfaces. nextElement (); System. out. println ("DisplayName:" + ni. getDisplayName (); System. out. println ("Name:" + ni. getName (); byte [] macs = ni. getHardwareAddress (); // The interface does not have a HardwareAddress. continue the next cycle if (macs = null) {continue;} for (int I = 0; I <macs. length; I ++) {mac = Integer. toHexString (macs [I] & 0xFF); if (mac. length () = 1) {mac = '0' + mac;} sb. append (mac + "-");} mac = sb. toString (); mac = mac. substring (0, mac. length ()-1); System. out. println (mac); Enumeration <InetAddress> ips = ni. getInetAddresses (); while (ips. hasMoreElements () {System. out. println ("IP:" + ips. nextElement (). getHostAddress () ;}} catch (SocketException e) {e. printStackTrace ();}}
Jdk1.6 is required for this method.