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" ));
}