linux下根据ip调用命令获取mac

来源:互联网 发布:计划提醒软件 编辑:程序博客网 时间:2024/05/16 01:33

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.LineNumberReader;


public class MACAddress {


public String getMac(String ip) throws IOException {

String mac = "not found!";

if (ip != null) {


try {

Process process = Runtime.getRuntime().exec(ip);

InputStreamReader ir = new InputStreamReader(process.getInputStream());

LineNumberReader input = new LineNumberReader(ir);

String line;

StringBuffer s = new StringBuffer();

while ((line = input.readLine()) != null) {

s.append(line);


}

mac = s.toString();

if (mac != null) {


mac = mac.substring(mac.indexOf(":") - 2, mac.lastIndexOf(":") + 3);


} else {

mac = "not found!";

}

return mac;


} catch (Exception e) {

e.printStackTrace();

}

}

return mac;


}

}

ps:

ip地址的获取:

HttpServletRequest request;

String ip = request.getRemoteAddr();

0 0
原创粉丝点击