Posted by: piman007 | 14-08-2007

Getting the Server Information of a LocalHost

    private String getServerInfo(){
        String strServerInfo = "";
        String strHostName   = "";
        String strHostAddress= "";
        try {
            InetAddress addr = InetAddress.getLocalHost();
            byte[] ipAddr   = addr.getAddress();
            strHostName     = addr.getHostName();
            // Convert to dot representation
            for (int i=0; i<ipAddr.length; i++) {
                if (i > 0) {
                    strHostAddress += ".";
                }
                strHostAddress += ipAddr[i]&0xFF;
            }
            strServerInfo = strHostName+"["+strHostAddress+"]";
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return strServerInfo;
    } 

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

หมวดหมู่

%d bloggers like this: