62,621
社区成员
发帖
与我相关
我的任务
分享public static String getIP() {
try {
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fc
.getExternalContext().getRequest();
return request.getRemoteAddr();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}这里取ip地址public static String getMac(String ip) {
String str = "";
String macAddress = "";
Process p;
try {
p = Runtime.getRuntime().exec("nbtstat -A " + 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) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return macAddress;
取macpublic static void main(String[] args) {
System.out.println( getMac( getIP()));
}运行出来