I have been using InetAddress.getLocalHost().getHostAddress(), how would I get this as a string?
Asked
Active
Viewed 295 times
0
-
the getHostAddress() returns String value. Then else do you need to be in String format? – Ankur Shanbhag Apr 19 '13 at 19:09
-
You've got as a String. Not a real question. – user207421 Apr 20 '13 at 01:06
1 Answers
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.
Or use InetAddress.getHostAddress()
as Nambari suggested.