Friday, 20 May 2011

detecting host name using java

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) {
    }

    }
}
out put
host name=system-1
Post a Comment