Java Hostname Lookup

From EggeWiki
Revision as of 20:47, 20 October 2009 by Brianegge (talk | contribs) (Created page with 'The following snippet shows how to get the hostname and IP address. <geshi lang="java"> public static void main(String[] args) throws UnknownHostException { java.net.InetAddr…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The following snippet shows how to get the hostname and IP address.

<geshi lang="java"> public static void main(String[] args) throws UnknownHostException { java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost(); System.out.println("Hostname of local machine: " + localMachine.getCanonicalHostName()); System.out.println("IP of local machine: " + localMachine.getHostAddress()); java.net.InetAddress localhost = java.net.InetAddress.getByName("localhost"); System.out.println("Hostname of localhost: " + localhost.getCanonicalHostName()); System.out.println("IP of localhost: " + localhost.getHostAddress()); }

Hostname of local machine: mail.theeggeadventure.com IP of local machine: 67.207.137.114 Hostname of localhost: localhost IP of localhost: 127.0.0.1 </geshi>