The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.net  [27 examples] > Hostnames and IP Addresses  [3 examples]

e146. Getting the IP Address and Hostname of the Local Machine

    try {
        InetAddress addr = InetAddress.getLocalHost();
    
        // Get IP Address
        byte[] ipAddr = addr.getAddress();
    
        // Get hostname
        String hostname = addr.getHostName();
    } catch (UnknownHostException e) {
    }

 Related Examples
e144. Getting the IP Address of a Hostname
e145. Getting the Hostname of an IP Address

See also: Datagram    Encodings    HTTP    Multicast    Sockets    URLs   


© 2002 Addison-Wesley.