JSP gets network IP address

Source: Internet
Author: User

Importjavax.servlet.http.HttpServletRequest; Public classremoteaddress { Public Staticstring Getrealclientip (HttpServletRequest request) {string IP= Request.getheader ("X-forwarded-for");        SYSTEM.OUT.PRINTLN (IP); if(IP = =NULL|| Ip.length () = = 0 | | "Unknown". Equalsignorecase (IP)) {IP= Request.getheader ("Proxy-client-ip");        SYSTEM.OUT.PRINTLN (IP); }        if(IP = =NULL|| Ip.length () = = 0 | | "Unknown". Equalsignorecase (IP)) {IP= Request.getheader ("Wl-proxy-client-ip");        SYSTEM.OUT.PRINTLN (IP); }        if(IP = =NULL|| Ip.length () = = 0 | | "Unknown". Equalsignorecase (IP)) {IP=request.getremoteaddr ();        SYSTEM.OUT.PRINTLN (IP); }        returnIP; }}

Before using the code as above to find that the results are 127.0.0.1, using this machine to do the server hanging online relay is also. Think it is code problems, and then directly hanging to the space, found that the normal display out of the network, and then use the mobile network to access the local server can also display IP is normal and no longer 127.0.0.1 or:: 1 of the IPV6 address.

JSP gets network IP address

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.