import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.struts2.ServletActionContext;public class Iputil {
public static String getIp(){
String ip = ServletActionContext.getRequest().getRemoteAddr();
return ip;
}
/**
* 获取网卡MAC地址
*/
public static String getMacOnWindow() {
try {
String mac = null;
Process process = Runtime.getRuntime().exec("ipconfig /all");
BufferedReader buffer = new BufferedReader(new InputStreamReader(process.getInputStream()));
for (String line = buffer.readLine(); line != null; line = buffer.readLine()) {
int index = line.indexOf("Physical Address");
if (index <= 0) {
continue;
}
mac = line.substring(index + 36);
break;
}
buffer.close();
process.waitFor();
return mac;
} catch (Exception exception) {
return null;
}
}
}
【java工具类】IPUtil
最新推荐文章于 2024-07-24 01:22:11 发布