2

I'm trying to get remote IP using this:

String remoteAddress = ((ServletRequestAttributes) RequestContextHolder
                .currentRequestAttributes()).getRequest().getRemoteAddr();

I call it in controller, but it returns 0:0:0:0:0:0:0:1. What's wrong?

Bimalesh Jha
  • 1,464
  • 9
  • 17
Tony
  • 3,605
  • 14
  • 52
  • 84

1 Answers1

6

0:0:0:0:0:0:0:1 is the loopback adress in IPv6. It's the equivalent of 127.0.0.1 in IPv4.

If you are using only one machine, this seems pretty normal to me. Otherwise, could you please give more details ?

EDIT

If you are trying to get your external (public) IP, then you could have a look at these SO posts :

Get real client IP in a Servlet

Getting the 'external' IP address in Java

How to get external IP successfully

Getting the IP address of the current machine using Java

In short, you can use request.getRemoteAddr(). But it won't return your public IP adress if you are on the same network.

Community
  • 1
  • 1
nha
  • 17,623
  • 13
  • 87
  • 133
  • This doesn't answer the question. Elaborate as to why he gets this result, or place it as a comment. – Jeroen Vannevel Sep 22 '13 at 14:58
  • Thank you for the comment. I'm pretty new to this (and just discovered that I can comment not). I've asked the OP for more details. – nha Sep 22 '13 at 15:00
  • What kind of details? – Tony Sep 22 '13 at 15:02
  • Like, what is the expected result? You were expecting a different IP adress ? One from another machine ? (Maybe I just don't get your question though) – nha Sep 22 '13 at 15:05