不能直接獲取到客戶端的mac地址,可以通過IP地址獲取客戶端的mac
先獲取IP地址,ip =?request.getRemoteAddr();?
通過ip地址獲取mac
public String getMACAddress(String ip) { ?
String str = ""; ?
String macAddress = ""; ?
try { ?
Process p = Runtime.getRuntime().exec("nbtstat -A " + ip); ?
InputStreamReader ir = new InputStreamReader(p.getInputStream()); ?
LineNumberReader input = new LineNumberReader(ir); ?
while((str = input.readLine()) != null){
if (str.indexOf("MAC") > 1) {
//使用substring函數截出mac地址
//macAddress = str.substring(str.indexOf("MAC") + 9, str.length()); ?
break; ?
} ?
} ?
} catch (IOException e) { ?
e.printStackTrace(System.out); ?
} ?
return macAddress; ?
} ?