Takes an URL-safe hostname and converts it to an address to be used in UDP sockets
16864
function getSocketAddressFromURLSafeHostname(hostname) {
    return __awaiter(this, void 0, void 0, function* () {
        // IPv4 addresses are fine
        if (net_1.isIPv4(hostname))
            return hostname;
        // IPv6 addresses are wrapped in [], which need to be removed
        if (/^\[.+\]$/.test(hostname)) {
            const potentialIPv6 = hostname.slice(1, -1);
            if (net_1.isIPv6(potentialIPv6))
                return potentialIPv6;
        }
        // This is a hostname, look it up
        try {
            const address = yield lookupAsync(hostname);
            // We found an address
            if (address)
                return address;
        }
        catch (e) {
            // Lookup failed, continue working with the hostname
        }
        return hostname;
    });
}
965036
def normalize_hostname(hostname):
    ''''''
    try:
        new_hostname = hostname.encode('idna').decode('ascii').lower()
    except UnicodeError as error:
        raise UnicodeError('Hostname {} rejected: {}'.format(hostname, error)) from error

    if hostname != new_hostname:
        # Check for round-trip. May raise UnicodeError
        new_hostname.encode('idna')

    return new_hostname
590661
def is_valid_url(value):
    
    match = URL_REGEX.match(value)
    host_str = urlparse(value).hostname
    return match and is_valid_host(host_str)
823115
def namespace_from_url(url):
    
    parsed = urlparse(url)
    if parsed.hostname is None or parsed.hostname in ['localhost', 'localhost.localdomain'] or (
            _ipv4_re.search(parsed.hostname)):
        return None

    namespace = parsed.hostname.split('.')
    namespace.reverse()
    if namespace and not namespace[0]:
        namespace.pop(0)
    if namespace and namespace[-1] == 'www':
        namespace.pop(-1)
    return type(url)('.'.join(namespace))
1112648
def build_url_base(host, port, is_https):
    
    base = "http"
    if is_https:
        base += 's'

    base += "://"
    base += host

    if port:
        base += ":"
        base += str(port)

    return base
489090
public static String normalizeHostName(String name) {
    try {
      return InetAddress.getByName(name).getHostAddress();
    } catch (UnknownHostException e) {
      return name;
    }
  }
515284
def to_s
      string = ''

      string += 'ws'
      string += 's' if self.secure
      string += '://'
      string += self.host
      string += ':' + self.port.to_s if self.port
      string += self.resource_name || '/'

      return string
    end
150303
def registry_hostname(registry):
    
    if registry.startswith('http:') or registry.startswith('https:'):
        return urlparse(registry).netloc
    else:
        return registry
1012960
def hostname=(new_hostname)
      if new_hostname &&
          (new_hostname.respond_to?(:ipv4?) || new_hostname.respond_to?(:ipv6?))
        new_hostname = new_hostname.to_s
      elsif new_hostname && !new_hostname.respond_to?(:to_str)
        raise TypeError, "Can't convert #{new_hostname.class} into String."
      end
      v = new_hostname ? new_hostname.to_str : nil
      v = "[#{v}]" if /\A\[.*\]\z/ !~ v && /:/ =~ v
      self.host = v
    end
65579
def _ipaddress_match(ipname, host_ip):
    
    # OpenSSL may add a trailing newline to a subjectAltName's IP address
    ip = ip_address(_unicode(ipname).rstrip())
    return ip == host_ip
460160
function(u){
      var urlObj = url.parse(u)
      return urlObj.protocol + "//" + urlObj.hostname + urlObj.pathname 
    }
502015
def _resolv_name(self, hostname):
        """"""
        ip = hostname
        try:
            ip = socket.gethostbyname(hostname)
        except Exception as e:
            logger.debug("{}: Cannot convert {} to IP address ({})".format(self.plugin_name, hostname, e))
        return ip
8341
def ip_to_host(ip):
    '''
    
    '''
    try:
        hostname, aliaslist, ipaddrlist = socket.gethostbyaddr(ip)
    except Exception as exc:
        log.debug('salt.utils.network.ip_to_host(%r) failed: %s', ip, exc)
        hostname = None
    return hostname
779798
private String parseHostAddress(String str)
	{
		String	header = "giop:tcp:";
		if (str.startsWith(header))
			str = str.substring(header.length());

		int		end = str.lastIndexOf(':');
		if (end>0)
			str = str.substring(0, end);
		return str;
	}
960733
function formatHostHeader (host, port, tls) {
  var defaultPort = tls ? 443 : 80
  var posColon = -1

  // For the Host header, ensure that IPv6 addresses are enclosed
  // in square brackets, as defined by URI formatting
  // https://tools.ietf.org/html/rfc3986#section-3.2.2
  if ((posColon = host.indexOf(':')) !== -1 &&
      (posColon = host.indexOf(':', posColon) !== -1) &&
      host[0] !== '[') {
    host = '[' + host + ']'
  }

  if (port && +port !== defaultPort) {
    host += ':' + port
  }

  return host
}
612230
public static String toSocketAddressString(String host, int port) {
        String portStr = String.valueOf(port);
        return newSocketAddressStringBuilder(
                host, portStr, !isValidIpV6Address(host)).append(':').append(portStr).toString();
    }
1270313
def add_host(zone, name, ttl, ip, nameserver='127.0.0.1', replace=True,
             timeout=5, port=53, **kwargs):
    '''
    
    '''
    res = update(zone, name, ttl, 'A', ip, nameserver, timeout, replace, port,
                 **kwargs)
    if res is False:
        return False

    fqdn = '{0}.{1}.'.format(name, zone)
    parts = ip.split('.')[::-1]
    popped = []

    # Iterate over possible reverse zones
    while len(parts) > 1:
        p = parts.pop(0)
        popped.append(p)
        zone = '{0}.{1}'.format('.'.join(parts), 'in-addr.arpa.')
        name = '.'.join(popped)
        ptr = update(zone, name, ttl, 'PTR', fqdn, nameserver, timeout,
                     replace, port, **kwargs)
        if ptr:
            return True
    return res