Re: [問題] 取得MacAddress

看板java作者 (克理斯@Internet)時間15年前 (2010/12/05 21:03), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
用 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
文章代碼(AID): #1C-usKLm (java)
文章代碼(AID): #1C-usKLm (java)