Java examples for Network:IP Address
Getting the IP Address and Hostname of the Local Machine
import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static void main(String[] args) { try {/*from ww w . j a v a 2 s . c o m*/ InetAddress addr = InetAddress.getLocalHost(); // Get IP Address byte[] ipAddr = addr.getAddress(); // Get hostname String hostname = addr.getHostName(); } catch (UnknownHostException e) { } } }