09 April 2012

get host name

import java.net.*;
import java.io.*;

public class GetHostName{
 public static void main(String [] args) {
 try {
  InetAddress addr = InetAddress.getLocalHost();
  byte[] ipAddr = addr.getAddress();
  String hostname = addr.getHostName();
  System.out.println("hostname="+hostname);
  } catch (UnknownHostException e) {
  }

  }
}

0 comments:

Post a Comment

Related Posts with Thumbnails

Popular Posts

 
;