public static String dumpLocalNetworkInfo ( ) throws UnknownHostException , SocketException { StringBuffer buffer = new StringBuffer ( ) ; InetAddress addr = InetAddress . getLocalHost ( ) ; buffer . append ( "Localhost: " + getAddrInfo ( addr ) + "\n" ) ; Enumeration < NetworkInterface > nifs = NetworkInterface . getNetworkInterfaces ( ) ; buffer . append ( "Network interfaces:\n" ) ; while ( nifs . hasMoreElements ( ) ) { NetworkInterface nif = nifs . nextElement ( ) ; buffer . append ( " - " + getNetworkInterfaceInfo ( nif ) + "\n" ) ; Enumeration < InetAddress > addresses = nif . getInetAddresses ( ) ; while ( addresses . hasMoreElements ( ) ) { addr = addresses . nextElement ( ) ; buffer . append ( " " + getAddrInfo ( addr ) + "\n" ) ; } } return buffer . toString ( ) ; }
Get the local network info as a string