When the project is released into the network, the host (such as IP address 192.168.10.88) accesses the URL of the LAN server, such as http://192.168.10.142:8080/index/, with request.getremoteaddr ( the host IP address obtained is 192.168.10.142, not the real IP address 192.168.10.88. To solve this problem, the following methods can be used to avoid this problem.
Public static string getipaddress (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 ()  ==&NBsp;0 | | "Unknown". Equalsignorecase (IP)) { ip = request.getheader ("Http_client_ip"); } if (ip == null | | ip.length () == 0 | | "Unknown". Equalsignorecase (IP)) { ip = request.getheader ("Http_x_forwarded_for"); } if (ip == null | | ip.length () == 0 | | "Unknown". Equalsignorecase (IP)) {  IP = REQUEST.GETREMOTEADDR (); } return ip.equals ("0:0:0:0:0:0:0:1") ? " 127.0.0.1 " : IP;    }
When the server and the host are the same machine, the obtained address is 0:0:0:0:0:0:0:1,0:0:0:0:0:0:0:1 is the representation of IPv6, corresponding to IPv4 equivalent to 127.0.0.1. Many of the arguments are that the #::1 localhost (IPv6) in the Hosts file (C:\Windows\System32\drivers\etc folder) is commented out and can get to 127.0.0.1, but I tried it without effect. So we used a three-mesh operator to assign a value of 127.0.01.
This article is from the "hualiued" blog, make sure to keep this source http://hualiued.blog.51cto.com/11510677/1887295
Java Get real IP address