Monday, October 29, 2012

IP and Machine Name of system in Java

Now Find your IP Address and Machine name with your domain in Java :

public class GetIPAddress {
  public static void main(String[] args) {
    try {
      InetAddress addressInstance = InetAddress.getLocalHost();
      System.out.println("IP Address : " + addressInstance.getHostAddress());
      System.out.println("System Name : " + addressInstance.getHostName());
      System.out.println("Canonical Host Name (Host name with the Domain): " + addressInstance.getCanonicalHostName());
      System.out.println("System Name with IP address : " + addressInstance.getLocalHost());
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}


No comments:

Post a Comment