Get Local IP Address and Hostname In Java

 Posted On  | Yashwant Chavan 

Below Example determine Local IP Address and Hostname of local computer using Java API. - class represents an Internet Protocol (IP) address. - Returns the address of the local host. This is achieved by retrieving the name of the host from the system, then resolving that name into an InetAddress. - Returns the IP address string in textual presentation. - Gets the host name for this IP address.



class IPAddressExample {
    public static void main(String args[]) throws Exception {
        InetAddress inetAddress = InetAddress.getLocalHost();
        System.out.println("IP Address:- " + inetAddress.getHostAddress());
        System.out.println("Host Name:- " + inetAddress.getHostName());


IP Address:-
Host Name:- swami-samartha

© 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0312 seconds.