Re: [問題] 取得MacAddress
用 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
推
12/05 21:33, , 1F
12/05 21:33, 1F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):