0

I have been using InetAddress.getLocalHost().getHostAddress(), how would I get this as a string?

millimoose
  • 37,888
  • 9
  • 76
  • 132

1 Answers1

1

To output an ip as string, from Justin Waugh's answer:

Simply call InetAddress.getByName(String host) passing in your textual IP address.

From the javadoc: The host name can either be a machine name, such as "java.sun.com", or a textual representation of its IP address.

InetAddress javadoc

Or use InetAddress.getHostAddress() as Nambari suggested.

Community
  • 1
  • 1
0x6C38
  • 6,583
  • 4
  • 34
  • 47