Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 30th, 2012  |  syntax: None  |  size: 0.39 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // netbeans
  2. // paulogp
  3. // get local host name and address
  4. import java.net.InetAddress;
  5. import java.net.UnknownHostException;
  6.  
  7. public class Main {
  8.         public static void main(String[] args) {
  9.                 try {
  10.                         System.out.println(InetAddress.getLocalHost().getHostName());
  11.                         System.out.println(InetAddress.getLocalHost().getHostAddress());
  12.                 } catch (UnknownHostException e) {
  13.                         System.err.println(e);
  14.                 }
  15.         }
  16. }