![]() ![]() A variation of the previous is to get the preferred FQDN from a config file or a command line parameter.(But how do you get it, and how do you deal with a DNS-based load balancer?) Another approach is to (somehow) get the externally advertised FQDN for the host, and use InetAddress.getByName() to look up the primary IP address.One approach is to use Java’s NetworkInterface.getNetworkInterfaces() API to get all of the known network interfaces on the host, and then iterate over each NI’s addresses.What this means is that the IP address returned by InetAddress.getLocalHost() might not be the right one to use. ![]() Some could be virtual devices, and others could be private network IP addresses. And to top that, not all IP addresses will be reachable from off the machine. The problem is that a host could have lots of network interfaces, and an interface could be bound to more than one IP address. On the face of it, InetAddress.getLocalHost() should give you the IP address of this host.
0 Comments
Leave a Reply. |