Use the InetAddress class.
InetAddress address = InetAddress.getLocalHost();
byte[] ip = address.getAddress();
// to get a string representation use
// the getHostAddress() method
String ipString = address.getHostAddress();
// for a string representation in
// form hostname/literal IP address
// use the toString() method
String hostAndIp = address.toString();
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment