import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
public class GetMACAddress {
public String getMACAddress(String ipAddress) {
String str = "", strMAC = "", macAddress = "";
try {
Process pp = Runtime.getRuntime().exec("nbtstat -a " + ipAddress);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for (int i = 1; i < 20; i++) {
str = input.readLine();
if (str != null) {
if (str.indexOf("MAC 地址") > 1) {
strMAC = str.substring(str.indexOf("MAC 地址") + 14,
str.length());
break;
}
}
}
} catch (IOException ex) {
return "Can't Get MAC Address!";
}
//
//if (strMAC.length() < 17) {
//return "Error!";
//}
macAddress = strMAC.substring(0, 2);
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载