public static InetAddress findLocalAddressViaNetworkInterface ( ) { Enumeration < NetworkInterface > networkInterfaces ; try { networkInterfaces = NetworkInterface . getNetworkInterfaces ( ) ; } catch ( SocketException e ) { return null ; } while ( networkInterfaces . hasMoreElements ( ) ) { NetworkInterface nif = networkInterfaces . nextElement ( ) ; for ( Enumeration < InetAddress > addrEnum = nif . getInetAddresses ( ) ; addrEnum . hasMoreElements ( ) ; ) { InetAddress interfaceAddress = addrEnum . nextElement ( ) ; if ( useInetAddress ( nif , interfaceAddress ) ) { return interfaceAddress ; } } } return null ; }
returns null if none has been found