Get host name, including the port, if defined

E.g. example.com:8080
169170
function getFullHost(): ?string
    {
        if ($this->host === null) {
            return null;
        }

        $fullHost = $this->host;

        if ($this->port !== null) {
            $fullHost .= ':' . $this->port;
        }

        return $fullHost;
    }
386636
def _get_hostname(self, hostname, metric):
        
        if hostname is None and self.label_to_hostname is not None:
            for label in metric.label:
                if label.name == self.label_to_hostname:
                    return label.value + self.label_to_hostname_suffix

        return hostname
1372686
def _host():
    """"""
    host_and_port = request.urlparts[1]
    try:
        host, _ = host_and_port.split(':')
    except ValueError:
        # No port yet. Host defaults to '127.0.0.1' in bottle.request.
        return DEFAULT_BIND
    return host or DEFAULT_BIND
136152
def get_hostname(url):
        

        if url not in URLHelper.__cache:
            URLHelper.__cache[url] = urlparse(url)

        parts = URLHelper.__cache[url].netloc.split(".")

        if len(parts) == 1:
            return parts[0]
        else:
            return ".".join(parts[-2:-1])
350391
def host_and_port(host_or_port):
    
    if ':' in host_or_port:
        if len(host_or_port) == 1:
            return 'localhost:4200'
        elif host_or_port.startswith(':'):
            return 'localhost' + host_or_port
        return host_or_port
    return host_or_port + ':4200'
832229
def server_hostname(self):
        
        result = c_char_p(
            self.lib.iperf_get_test_server_hostname(self._test)
        ).value
        if result:
            self._server_hostname = result.decode('utf-8')
        else:
            self._server_hostname = None
        return self._server_hostname
1114472
def hostloc(self):
        """"""
        hostloc = self.hostname
        if self.port:
            hostloc = '{hostloc}:{port}'.format(hostloc=hostloc, port=self.port)

        return hostloc
17464
function ___GET_ENV_HOSTNAME() {
	try {
		if ( HAS_NODE_BUFFER ) {
			return require( 'os' ).hostname;
		}
		else
		if ( typeof window !== "undefined" ) {
			return window.location.hostname;
		}
		else {
			throw new Error("");
		}
	}
	catch(e) {
		return 'unknown.' + DumpHexStringLE(RandomBytes(32));
	}
}
587298
private static String getHostAddress(InetSocketAddress addr) {
    String hostToAppend = "";
    if (addr.isUnresolved()) {
      hostToAppend = addr.getHostName();
    } else {
      hostToAppend = addr.getAddress().getHostAddress();
    }
    return hostToAppend;
  }
170191
public static String getHostName(String _ipAddress) {
        try {
            InetAddress addr = InetAddress.getByName(_ipAddress);
            return addr.getHostName();
        } catch (Exception _ex) {
            return _ipAddress;
        }
    }
1025797
private static String getHostName() {
    String hostName = null;
    try {
      hostName = InetAddress.getLocalHost().getHostName();
    } 
    catch (UnknownHostException ex) {
      LOG.info("Unable to obtain hostName", ex);
      hostName = "unknown";
    }
    return hostName;
  }
960112
def get_self_host(request_data):
        
        if 'http_host' in request_data:
            current_host = request_data['http_host']
        elif 'server_name' in request_data:
            current_host = request_data['server_name']
        else:
            raise Exception('No hostname defined')

        if ':' in current_host:
            current_host_data = current_host.split(':')
            possible_port = current_host_data[-1]
            try:
                possible_port = float(possible_port)
                current_host = current_host_data[0]
            except ValueError:
                current_host = ':'.join(current_host_data)

        return current_host
743879
def hostname_for_event(self, clean_server_name):
        """"""
        uri = urlsplit(clean_server_name)
        if '@' in uri.netloc:
            hostname = uri.netloc.split('@')[1].split(':')[0]
        else:
            hostname = uri.netloc.split(':')[0]
        if hostname == 'localhost':
            hostname = self.hostname
        return hostname
1055407
def get_port_by_name(self, port_name):
        ''''''
        with self._mutex:
            for p in self.ports:
                if p.name == port_name:
                    return p
            return None
357523
def _parse_hostname(self):
        
        value = 'localhost'
        match = re.search(r'^hostname ([^\s]+)$', self.config, re.M)
        if match:
            value = match.group(1)
        return dict(hostname=value)
335145
def _get_hostname(self, hostname, sample, scraper_config):
        
        if (
            hostname is None
            and scraper_config['label_to_hostname'] is not None
            and scraper_config['label_to_hostname'] in sample[self.SAMPLE_LABELS]
        ):
            hostname = sample[self.SAMPLE_LABELS][scraper_config['label_to_hostname']]
            suffix = scraper_config['label_to_hostname_suffix']
            if suffix is not None:
                hostname += suffix

        return hostname
306735
def get_full_name(self):
        
        if self.is_tpl():
            return "tpl-%s/%s" % (getattr(self, 'host_name', 'XxX'), self.name)
        if hasattr(self, 'host_name') and hasattr(self, 'service_description'):
            return "%s/%s" % (self.host_name, self.service_description)
        return 'UNKNOWN-SERVICE'