code: public static String hostNameFrom(final Connection connection) {
          if (connection instanceof IIOPConnection) {
              final IIOPConnection iiopConnection = (IIOPConnection) connection;
              return iiopConnection.getSocket().getInetAddress().getHostName();
          } else if (connection instanceof IIOPLoopbackConnection) {
              try {
                  return InetAddress.getLocalHost().getCanonicalHostName();
              } catch (final UnknownHostException e) {
                  return "localhost";
              }
          }
          throw new IllegalStateException("Unknown connection type: " + connection.getClass());
      }
docs: Get host name from a {@link Connection}
  
  @param connection
  @return