static InetAddress [ ] getGlobalInterfaces ( ) throws SocketException { List < InetAddress > list = new ArrayList < InetAddress > ( ) ; for ( NetworkInterface intf : getInterfaces ( ) ) { if ( intf . isUp ( ) ) { for ( InetAddress address : Collections . list ( intf . getInetAddresses ( ) ) ) { if ( address . isLoopbackAddress ( ) == false && address . isSiteLocalAddress ( ) == false && address . isLinkLocalAddress ( ) == false ) { list . add ( address ) ; } } } } return list . toArray ( new InetAddress [ list . size ( ) ] ) ; }
Returns all global scope addresses for interfaces that are up .