FileDocCategorySizeDatePackage
NetUtils.javaAPI DocAzureus 3.0.3.42040Mon Dec 11 12:35:06 GMT 2006com.aelitis.azureus.core.util

NetUtils

public class NetUtils extends Object

Fields Summary
Constructors Summary
Methods Summary
public static java.net.InetAddressgetLocalHost()

		try{
			return( InetAddress.getLocalHost());
			
		}catch( Throwable e ){
			
				// sometimes get this when changing host name
				// return first non-loopback one
			
			try{
				Enumeration 	nis = NetworkInterface.getNetworkInterfaces();

				while( nis.hasMoreElements()){
					
					NetworkInterface	 ni = (NetworkInterface)nis.nextElement();
						
					Enumeration addresses = ni.getInetAddresses();
					
					while( addresses.hasMoreElements()){
						
						InetAddress address = (InetAddress)addresses.nextElement();
						
						if ( address.isLoopbackAddress() || address instanceof Inet6Address ){
							
							continue;
						}
						
						return( address );
					}
				}
			}catch( Throwable f ){
			}
			
			return( InetAddress.getByName( "127.0.0.1" ));
		}