Retrieves the cluster host address from the UrlParser instance.

@param urlParser object that holds the connection information
@return cluster host address
324607
private HostAddress findClusterHostAddress(UrlParser urlParser) throws SQLException {
    List<HostAddress> hostAddresses = urlParser.getHostAddresses();
    Matcher matcher;
    for (HostAddress hostAddress : hostAddresses) {
      matcher = auroraDnsPattern.matcher(hostAddress.host);
      if (matcher.find()) {

        if (clusterDnsSuffix != null) {
          //ensure there is only one cluster
          if (!clusterDnsSuffix.equalsIgnoreCase(matcher.group(3))) {
            throw new SQLException("Connection string must contain only one aurora cluster. "
                + "'" + hostAddress.host + "' doesn't correspond to DNS prefix '" + clusterDnsSuffix
                + "'");
          }
        } else {
          clusterDnsSuffix = matcher.group(3);
        }

        if (matcher.group(2) != null && !matcher.group(2).isEmpty()) {
          //not just an instance entry-point, but cluster entrypoint.
          return hostAddress;
        }
      } else {
        if (clusterDnsSuffix == null
            && hostAddress.host.contains(".")
            && !Utils.isIPv4(hostAddress.host)
            && !Utils.isIPv6(hostAddress.host)) {
          clusterDnsSuffix = hostAddress.host.substring(hostAddress.host.indexOf(".") + 1);
        }
      }
    }
    return null;
  }
809476
public static String getHost(InetSocketAddress addr) {
    try {
      Method getHostStringMethod = InetSocketAddress.class.getMethod("getHostString");
      return (String) getHostStringMethod.invoke(addr);
    } catch (NoSuchMethodException e) {
      // noop
    } catch (IllegalAccessException e) {
      // noop
    } catch (InvocationTargetException e) {
      // noop
    }
    return addr.getHostName();
  }
417104
public static String getLocalhost() throws RuntimeException
	{
		String hostname = null;

		try
		{
			InetAddress addr = InetAddress.getLocalHost();

			hostname = addr.getHostName();
		}
		catch (UnknownHostException e)
		{
			throw new RuntimeException("[FileHelper] {getLocalhost}: Can't get local hostname");
		}

		return hostname;
	}
737646
private static String[] getCLDBLocations(String authority) throws IOException {

		// Determine the MapR home
		String maprHome = System.getenv(MAPR_HOME_ENV);
		if (maprHome == null) {
			maprHome = DEFAULT_MAPR_HOME;
		}

		final File maprClusterConf = new File(maprHome, MAPR_CLUSTER_CONF_FILE);

		if (LOG.isDebugEnabled()) {
			LOG.debug(String.format(
					"Trying to retrieve MapR cluster configuration from %s",
					maprClusterConf));
		}

		if (!maprClusterConf.exists()) {
			throw new IOException("Could not find CLDB configuration '" + maprClusterConf.getAbsolutePath() +
					"', assuming MapR home is '" + maprHome + "'.");
		}

		// Read the cluster configuration file, format is specified at
		// http://doc.mapr.com/display/MapR/mapr-clusters.conf

		try (BufferedReader br = new BufferedReader(new FileReader(maprClusterConf))) {

			String line;
			while ((line = br.readLine()) != null) {

				// Normalize the string
				line = line.trim();
				line = line.replace('\t', ' ');

				final String[] fields = line.split(" ");
				if (fields.length < 1) {
					continue;
				}

				final String clusterName = fields[0];

				if (!clusterName.equals(authority)) {
					continue;
				}

				final List<String> cldbLocations = new ArrayList<>();

				for (int i = 1; i < fields.length; ++i) {

					// Make sure this is not a key-value pair MapR recently
					// introduced in the file format along with their security
					// features.
					if (!fields[i].isEmpty() && !fields[i].contains("=")) {
						cldbLocations.add(fields[i]);
					}
				}

				if (cldbLocations.isEmpty()) {
					throw new IOException(
							String.format(
									"%s contains entry for cluster %s but no CLDB locations.",
									maprClusterConf, authority));
				}

				return cldbLocations.toArray(new String[cldbLocations.size()]);
			}

		}

		throw new IOException(String.format(
				"Unable to find CLDB locations for cluster %s", authority));
	}
834979
def get_host(url):
    
    # This code is actually similar to urlparse.urlsplit, but much
    # simplified for our needs.
    port = None
    scheme = 'http'
    if '//' in url:
        scheme, url = url.split('://', 1)
    if '/' in url:
        url, _path = url.split('/', 1)
    if ':' in url:
        url, port = url.split(':', 1)
        port = int(port)
    return scheme, url, port
861405
public static InetAddress getLocalAddress() throws UnknownHostException, SocketException {
        InetAddress addr = InetAddress.getLocalHost();
        NetworkInterface nif = NetworkInterface.getByInetAddress(addr);
        if (addr.isLoopbackAddress() || addr instanceof Inet6Address || nif == null) {
            // Find local address that isn't a loopback address
            InetAddress lookedUpAddr = findLocalAddressViaNetworkInterface();
            // If a local, multicast enabled address can be found, use it. Otherwise
            // we are using the local address, which might not be what you want
            addr = lookedUpAddr != null ? lookedUpAddr : InetAddress.getByName("127.0.0.1");
        }
        return addr;
    }
823691
public static String urlToHost(String url) {
		String lcUrl = url.toLowerCase();
		if(lcUrl.startsWith(DNS_SCHEME)) {
			return lcUrl.substring(DNS_SCHEME.length());
		}
		for(String scheme : ALL_SCHEMES) {
			if(lcUrl.startsWith(scheme)) {
				int authorityIdx = scheme.length();

				Matcher m = 
					HOST_REGEX_SIMPLE.matcher(lcUrl.substring(authorityIdx));
				if(m.find()) {
					return m.group(1);
				}
			}
		}
		return url;
	}
244545
protected String getHostname(String url) {
        if (log.isDebugEnabled()) {
            log.debug("getHostname - url: {}", url);
        }
        String[] parts = url.split("/");
        if (parts.length == 2) {
            return "";
        } else {
            String host = parts[2];
            // strip out default port in case the client added the port explicitly
            if (host.endsWith(":1935")) {
                // remove default port from connection string
                return host.substring(0, host.length() - 5);
            }
            return host;
        }
    }
181135
public String getRemoteHost()
    {
        if (_remoteHost==null)
        {
            if (_resolveRemoteHost)
            {
                if (_remoteInetAddress==null)
                    return "localhost";
                _remoteHost=_remoteInetAddress.getHostName();
            }
            else
            {
                if (_remoteInetAddress==null)
                    return "127.0.0.1";
                _remoteHost=getRemoteAddr();
            }
        }
        return _remoteHost;
    }
1350700
public Address[] getAddresses() {
    if (addresses != null)
      return addresses;

    if (hosts != null) {
      addresses = new Address[hosts.length];
      for (int i = 0; i < hosts.length; i++)
        addresses[i] = new Address(hosts[i], factory.getPort());
      return addresses;
    }

    Address address = factory == null ? new Address("localhost", -1) : new Address(
        factory.getHost(), factory.getPort());
    return new Address[] { address };
  }
573994
public static InetAddress getLocalIPAddress() {
        Enumeration<NetworkInterface> enumeration = null;
        try {
            enumeration = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
            e.printStackTrace();
        }
        if (enumeration != null) {
            while (enumeration.hasMoreElements()) {
                NetworkInterface nif = enumeration.nextElement();
                Enumeration<InetAddress> inetAddresses = nif.getInetAddresses();
                if (inetAddresses != null) {
                    while (inetAddresses.hasMoreElements()) {
                        InetAddress inetAddress = inetAddresses.nextElement();
                        if (!inetAddress.isLoopbackAddress() && isIPv4Address(inetAddress.getHostAddress())) {
                            return inetAddress;
                        }
                    }
                }
            }
        }
        return null;
    }
1334242
public <T> Link<T> get(final SocketAddress remoteAddr) {
    final LinkReference linkRef = this.addrToLinkRefMap.get(remoteAddr);
    return linkRef != null ? (Link<T>) linkRef.getLink() : null;
  }
1130949
public static String getHostName(SocketAddress socketAddress) {
        if (socketAddress == null) {
            return null;
        }

        if (socketAddress instanceof InetSocketAddress) {
            InetAddress addr = ((InetSocketAddress) socketAddress).getAddress();
            if(addr != null){
                return addr.getHostAddress();
            }
        }

        return null;
    }
469499
def url_host(url: str) -> str:
    
    from urllib.parse import urlparse
    res = urlparse(url)
    return res.netloc.split(':')[0] if res.netloc else ''
32212
public static InetAddress getLocalIpAddress() throws RuntimeException
	{
		try
		{
			List<InetAddress> ips = getLocalIpAddresses(false, true);

			for (InetAddress ip : ips)
			{
				log.debug("[IpHelper] {getLocalIpAddress} Considering locality of " + ip.getHostAddress());
				if (!ip.isAnyLocalAddress() && (ip instanceof Inet4Address))
				{
					// Ubuntu sets the unix hostname to resolve to 127.0.1.1; this is annoying so treat it as a loopback
					if (!ip.getHostAddress().startsWith("127.0."))
					{
						log.debug("[IpHelper] {getLocalIpAddress} Found nonloopback IP: " + ip.getHostAddress());
						return ip;
					}
				}
			}

			log.trace("[IpHelper] {getLocalIpAddress} Couldn't find a public IP in the ip (size " + ips.size() + ")");
			return InetAddress.getLocalHost();
		}
		catch (UnknownHostException e)
		{
			throw new RuntimeException("[FileHelper] {getLocalIp}: Unable to acquire the current machine's InetAddress", e);
		}
	}
137347
public static UrlBuilder parse(String url) {
        final UrlBuilder result = new UrlBuilder();
        result.with(url, UrlTokenizerState.SCHEME_OR_HOST);
        return result;
    }
1147380
public String getServerAddr()
    {
        if (_connection instanceof Socket)
            return ((Socket)_connection).getLocalAddress().getHostAddress();
        return _listener.getHost();
    }