Using request.getRemoteAddr() returns 0:0:0:0:0:0:0:1

前端 未结 3 733
挽巷
挽巷 2020-12-13 06:17

I am trying to print the IP adress of the logged user in my webApplication. If a user connects from another PC (which is under the same network, as the web application is ru

相关标签:
3条回答
  • 2020-12-13 06:20

    As we move over to IPv6 from IPv4, they are changing the loopback address (localhost) to 0:0:0:0:0:0:0:1 from 127.0.0.1 thats why you are getting this address.

    As for the functions:

    • getRemoteAddr() returns the clients IP

    • getLocalAddr() returns the IP of the server the application is running on

    0 讨论(0)
  • 2020-12-13 06:36

    In your case, as you are trying to access it on your local machine,so it will return that value. But let one of your friend access it, and you will receive the expected result with getRemoteAddr

    From the javadoc:

    getRemoteAddr - Returns the IP address of the client or last proxy that sent the request

    getLocalAddr - Returns the IP address of the interface on which the request was received.

    0 讨论(0)
  • 2020-12-13 06:38

    getRemoteAddr() solves your purpose but if client is behind any proxy then you will get IP address of proxy :

    Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.

    getLocalAddr() returns the IP of the server the application is running on.

    0 讨论(0)
提交回复
热议问题