Servlet获取客户端的IP与MAC地址
来源:互联网 发布:淘宝的飞猪旅行可靠吗 编辑:程序博客网 时间:2024/05/01 04:34
public class CheckMACandIP extends HttpServlet {
public CheckMACandIP() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String ip = getRemoteAddress(request);
System.out.println(ip);
System.out.println(getMACAddress(ip));
}
public void init() throws ServletException {
}
public String getRemoteAddress(HttpServletRequest request){
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getHeader("Proxy-Client-IP");
if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getHeader("WL-Proxy-Client-IP");
if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getRemoteAddr();
return ip;
}
public String getMACAddress(String ip){
String str = "";
String macAddress = "";
try {
Process 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) {
e.printStackTrace(System.out);
}
return macAddress;
}
}
- Servlet获取客户端的IP与MAC地址
- Servlet获取客户端的IP与MAC地址
- 获取客户端的IP与MAC地址
- 如何获取客户端的IP与MAC地址
- 获取客户端的IP地址和Mac地址
- js获取客户端网卡的IP地址、MAC地址
- 获取客户端网卡MAC地址和IP地址的方法
- C# 获取客户端的IP地址和MAC地址
- 客户端和服务器端的IP、MAC地址等的获取
- C#通过Web获取客户端的IP与Mac地址实现
- 获取客户端ip和mac地址的方法总结
- Java获取访问服务端的客户端IP和MAC地址
- JAVASCRIPT获取客户端IP及MAC地址
- js 获取客户端ip mac地址
- java 获取客户端ip mac地址
- jsp获取客户端ip和mac地址
- java 获取客户端ip mac地址
- Java获取客户端ip mac地址
- Asterisk安装
- 编译 Linux2.6 内核总结
- windows中不能实现文件共享的解决办法
- 使用svn搭建服务器,客户端使用
- ASP.NET数据绑定概述和语法
- Servlet获取客户端的IP与MAC地址
- Linux 简介
- CFStringRef to cstring in c++
- C#操作Excel:不存在类型或命名空间名称“Interop”(
- javaDB—— derby简单操作
- JAVA排序汇总
- MultiByteToWideChar
- Windows 平台上长路径名文件的解决方法
- MySQL注意事项(字符连接,IN)