local Canonical Host Name - Java Network

Java examples for Network:Host

Description

local Canonical Host Name

Demo Code


//package com.java2s;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(localFqdn());
    }/*  w ww. j  a va2s .c  om*/

    public static String localFqdn() {
        try {
            return InetAddress.getLocalHost().getCanonicalHostName();
        } catch (UnknownHostException e) {
            return null;
        }
    }
}

Related Tutorials