Oct
01
|
Use the getNetworkInterfaces() method of the NetworkInterface class to get all the network interfaces, and then loop thru each interface to get the ip addresses associated with that interface.
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface networkInterface = networkInterfaces.nextElement(); List<InterfaceAddress> addresses = networkInterface.getInterfaceAddresses(); for (InterfaceAddress address : addresses) { InetAddress inetAddress = address.getInetAddress(); System.out.println("Name: "+ inetAddress.getHostName()); System.out.println("Address: "+ inetAddress.getHostAddress()); } }
Array ( ) One Response to “How can I find all the ip address’s associated with the local host?”
Leave a Reply
You must be logged in to post a comment.
April 22nd, 2011 at 3:44 pm
Really a nice post. Helped me alot. This requires java 1.6 version.