1

I am trying the following code to get my ip address in a jsp page:

<%
        out.println("Your IP address is " + request.getRemoteAddr());
%>

This prints 0:0:0:0:0:0:0:1, not my ip address. Is this what is suposed to be? Why is not it showing my ip address?

Thanks

yrazlik
  • 10,411
  • 33
  • 99
  • 165

2 Answers2

2

That's your IP address, but not a IPv4 (xx.xx.xx.xx) but a IPv6 one (xx:xx:xx:xx:xx:xx:xx:xx)

EDIT: if your system is mapping IPv4 from/to IPv6 you can infer the algorithm to change between them by reading this

morgano
  • 17,210
  • 10
  • 45
  • 56
  • @bigO [wikipedia's article for IPv6](http://en.wikipedia.org/wiki/Ipv6) mentions a mapping convention between IPv6 and IPv4 and how to do it – morgano Jul 01 '13 at 20:14
-2

JSP code:

<html>
<head><title>Hello World</title></head>
<body>
    Hello World!<br/>
    <%
        out.println("Your Host IP address is " + request.getRemoteHost()+"</br>");
        out.println("Your Addr address is " + request.getRemoteAddr()+"</br>");
        out.println("Your Port Post address is " + request.getRemotePort()+"</br>");
    %>
</body>
</html>

Use http://127.0.0.1:8081/hello.jsp gets the result:

Hello World!
Your Host IP address is 0:0:0:0:0:0:0:1
Your Addr address is 0:0:0:0:0:0:0:1
Your Port Post address is 32432

Use http://localhost:8081/hello.jsp gets the result:

Hello World!
Your Host IP address is 0:0:0:0:0:0:0:1
Your Addr address is 0:0:0:0:0:0:0:1
Your Port Post address is 32432
Bruce Yo
  • 152
  • 1
  • 12