Get the local IP address using Java.
There are many ways to get the local IP address using Java. And we are going to examine various methods. On the face of it, InetAddress.getLocalHost() should give you the IP address of this host. But it doesn't. One of the major problems are that a host could have lots of network interfaces, and an interface could be bound to more than one IP address. And to top that, not all IP addresses will be reachable outside of your machine or your LAN. For example, they could be IP addresses for virtual network devices, private network IP addresses, and so on. Following method use opendns.com to get the local IP address. package learnjava.System; /** * Created by Isuru on 11/04/2017. */ import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; // class with main() method public class IPAddress { public static void main(String[] args) { String ipAdressDns = "" ; try { String command = "nslookup myi...