get My Host Name from InetAddress - Java Network

Java examples for Network:Network Address

Description

get My Host Name from InetAddress

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(getMyHostName());
    }// w ww.j  a  v a2s.c om

    public static String getMyHostName() throws UnknownHostException {
        return getMyAddress().getHostName();
    }

    public static InetAddress getMyAddress() throws UnknownHostException {
        return InetAddress.getLocalHost();
    }
}

Related Tutorials