1 import java.net.InetAddress; 2 import java.net.NetworkInterface; 3 import java.net.SocketException; 4 import java.net.UnknownHostException; 5 6 public class MacAddress { 7 8 /** 9 * @param args10 * @throws UnknownHostException 11 * @throws SocketException 12 */13 public static void main(String[] args) throws UnknownHostException, SocketException {14 15 InetAddress ia = InetAddress.getLocalHost();16 System.out.println(ia);17 getLocalMac(ia);18 }19 private static void getLocalMac(InetAddress ia) throws SocketException {20 // TODO Auto-generated method stub21 //获取网卡,获取地址22 byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress();23 24 System.out.println("mac数组长度:"+mac.length);25 StringBuffer sb = new StringBuffer("");26 for(int i=0; i
下面这个方法是获取客户端请求地址
public String getClientIp(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } if(ip.trim().contains(",")){ String [] ips=ip.split(","); ip=ips[0]; } return ip; }