0

I'm trying to convert InetAddress.getLocalHost() to String but it gets a different address. When I use InetAddress.getLocalHost(), I get my real IP address, but when I use InetAddress.getLocalHost().toString() it's some different address that I don't know.

This is my code:

  String ipAddr = StringUtils.substringAfter((String) InetAddress.getLocalHost(), "/");
  String host = InetAddress.getLocalHost().getHostAddress();

My real IP address is 172.xxx.xxx.xxx, but when I convert to string, I get 168.xxx.xxx.xxx. How can I get my real IP address, that is, my IP address from my local machine?

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
None
  • 7,955
  • 22
  • 81
  • 154

0 Answers0