什么都不多说直接上代码....其实很简单...可以到Windows的cmd中测试下是否可以获取成功
public String getMACAddress(String ip){
String str = "";
String macAddress = "";
try {
String sep=System.getProperties().getProperty("file.separator");
String scancmd="nbtstat -A";
if(sep.equals("/"))
scancmd="nmblookup -A";
Process p = Runtime.getRuntime().exec(scancmd + ip);
InputStreamReader ir = new InputStreamReader(p.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for (int i = 1; i < 100; i++) {
str = input.readLine();
if (str != null) {
if (str.indexOf("MAC Address") > 1) {
macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length());
break;
}
}
}
} catch (IOException e) {
e.printStackTrace(System.out);
}
return macAddress;
}