/**
* 根据ip获取电脑mac地址
* @param ip
* @return 电脑mac地址
*/
public String getMACAddress(String ip) {
String macAddress = "";
Process p = null;
Runtime runtime = java.lang.Runtime.getRuntime();
try {
p = runtime.exec("nbtstat -A " + ip);
} catch (IOException e2) {
//这句话在windows电脑上正常,但是苹果电脑上会报错:java.io.IOException: Cannot run program "nbtstat": error=2, No such file or directory
log.error("FunMethod getMACAddress Runtime error============"+e2.getMessage());
}
if(p!=null){
InputStreamReader ir = new InputStreamReader(p.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for (int i = 1; i < 100; i++) {
String str = null;
try {
str = input.readLine();
} catch (IOException e) {
log.error("FunMethod getMACAddress readLine error============"+e.getMessage());
}
if (str != null) {
if (str.indexOf("MAC Address") > 1) {
macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length());
break;
}
}
}
}
return macAddress;
}