方法一:
調用Windows的DOS命令,從輸出結果中讀取MAC地址:
public static String getMACAddress() {
String address = "";
String os = System.getProperty("os.name");
if ( os != null && os.startsWith("Windows")) {
try {
String command = "cmd.exe /c ipconfig /all";
Process p = Runtime.getRuntime().exec(command);
BufferedReader br =
new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
if (line.indexOf("Physical Address") > 0) {
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
break;
}
}
br.close();
return address.trim();
}
catch (IOException e) { }
}
return address;
}
We can replace the "ipconfig" to "ping x.x.x.x" and "arp -a"...We can get the mac list...haha!!
缺點:只能取得服務器端MAC地址.如果要取得客戶端的MAC地址,需用Applet.只針對MS-WIN系統.
?
方法二:
可以用JS或vbscript來調用WMI接口來獲取Client端的MAC地址.
?
?
WMI Scripting HTML?
?
?
?
?
??
??
??
??
?
忘了附上原文的出處了:
How to get IP address of the browser when its operating behind a proxy/firewall? (applets...activex....??)
http://www.faqts.com/knowledge_base/view.phtml/aid/9005/fid/125
關于WMI的詳細信息可以參看MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_tasks_for_scripts_and_applications.asp
平心而論,WMI的很強大的。原先需要動用重量級編程工具才能做到的事,現在用js/vbscript就可以做了。
獲取多塊網卡的MAC地址:
if(objObject.MACAddress != null && objObject.MACAddress != "undefined"){
???????????????????????? MACAddr = objObject.MACAddress;
???????????????????????? alert( MACAddr );
?????????????????? }
缺點:需要ActiveX支持.對MS-WIN系統有效.
方法三:
想137口發送UDP查詢:
WINDOWS平臺的客戶端(當獲取時它轉換為服務端角色),NETBIOS協議在137口上,我們只要向它的137口發送UDP查詢,獲取它的返回值就可以獲取到它所有的網卡地址.
以上內容來自dev2dev的討論帖:
http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=121&threadID=12941&tstart=0
?
posted on 2005-01-20 08:50
eamoi 閱讀(5175)
評論(1) 編輯 收藏 所屬分類:
Java