23,407
社区成员
发帖
与我相关
我的任务
分享package tools;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
public class MacAddressSearcher {
public static String getMacAddress(String ip) {
String str = "";
String macAddress = "";
LineNumberReader lnReader = null;
try {
Process process = Runtime.getRuntime().exec("nbtstat -A " + ip);
lnReader = new LineNumberReader(new InputStreamReader(process.getInputStream()));
for (int i = 1; i < 100; i++) {
str = lnReader.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();
} finally {
try {
lnReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return macAddress;
}
public static void main(String[] args) {
System.out.println(MacAddressSearcher.getMacAddress("192.168.16.239"));
}
}