我遇到一个简单问题的麻烦.我会在HTTPServlet中获得真正的客户端IP.
从现在起我用过:
request.getRemoteAddr()
Run Code Online (Sandbox Code Playgroud)
但现在它返回一个虚假的IP.例如:xxx.xxx.xxx.50,但我的IP类似于xxx.xxx.xxx.159.(查看http://whatismyipaddress.com/).
现在我试着用:
request.getHeader("X-Forwarded-For")
Run Code Online (Sandbox Code Playgroud)
它返回NULL.
我还参加了以下课程的探测:
public class IpUtils {
public static final String _255 = "(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
public static final Pattern pattern = Pattern.compile("^(?:" + _255 + "\\.){3}" + _255 + "$");
public static String longToIpV4(long longIp) {
int octet3 = (int) ((longIp >> 24) % 256);
int octet2 = (int) ((longIp >> 16) % 256);
int octet1 = (int) ((longIp >> 8) % 256);
int octet0 = …Run Code Online (Sandbox Code Playgroud)