推 averywu:感謝您!我會用心學習每行的功能的 12/05 21:33
用 macbook 跑了一下 , 並且我是預設不知道 interface 的名稱
import java.net.*;
import java.util.Enumeration;
public class
GetHardwareAddress {
/**
* @param 取得 mac address
*/
public static void main(String args[]) throws Exception {
Enumeration interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) interfaces.nextElement();
NetworkInterface networkInterface = NetworkInterface.getByName(ni.getName());
byte b1[] = networkInterface.getHardwareAddress();
System.out.print("Hardware Address = ");
if (b1!=null)
for (int i = 0; i < b1.length; i++)
System.out.print(b1[i]);
} //end while , quit interfaces.hasMoreElemetns()
}
}
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.116.38.91