top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Get the localhost IP address in Java ?

0 votes
289 views
How to Get the localhost IP address in Java ?
posted Jun 16, 2016 by Sathyasree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
package com.abundantcode;
import java.net.InetAddress;

public class Main {

    public static void main(String[] args)
    {
        try
        {
            InetAddress ipObj = InetAddress.getLocalHost();
            System.out.println(ipObj.getHostAddress());
        }
        catch (Exception ex)
        {
            System.out.println(ex.getStackTrace());
        }
    }
}
answer Jun 16, 2016 by Shivaranjini
Similar Questions
+1 vote

I want a JAVA program. That gets the website name from the user and prints the IP Address of that website.

+3 votes

Any opensource code would be a great help :)

+1 vote
...