public static List < InetAddress > getLocalIpAddresses ( boolean pruneSiteLocal , boolean pruneDown ) throws RuntimeException { try { Enumeration < NetworkInterface > nics = NetworkInterface . getNetworkInterfaces ( ) ; List < InetAddress > addresses = new Vector < InetAddress > ( ) ; while ( nics . hasMoreElements ( ) ) { NetworkInterface iface = nics . nextElement ( ) ; Enumeration < InetAddress > addrs = iface . getInetAddresses ( ) ; if ( ! pruneDown || iface . isUp ( ) ) { while ( addrs . hasMoreElements ( ) ) { InetAddress addr = addrs . nextElement ( ) ; if ( ! addr . isLoopbackAddress ( ) && ! addr . isLinkLocalAddress ( ) ) { if ( ! pruneSiteLocal || ( pruneSiteLocal && ! addr . isSiteLocalAddress ( ) ) ) { addresses . add ( addr ) ; } } } } } return addresses ; } catch ( SocketException e ) { throw new RuntimeException ( e . getMessage ( ) , e ) ; } }
Returns a list of local InetAddresses for this machine