Java Utililty Methods Host Name Get

List of utility methods to do Host Name Get

Description

The list of methods to do Host Name Get are organized into topic(s).

Method

StringgetLocalCanonicalHostName()
get Local Canonical Host Name
InetAddress localMachine = InetAddress.getLocalHost();
return localMachine.getCanonicalHostName();
StringgetLocalShortHostName()
get Local Short Host Name
if (cachedShortHostName != null) {
    return cachedShortHostName;
try {
    String hostName;
    InetAddress iAddress = InetAddress.getLocalHost();
    hostName = iAddress.getHostName();
    String[] parts = hostName.split("\\.");
...
StringgetLogHost()
get Log Host
InetAddress address = LOCAL_ADDRESS;
return address == null ? LOCALHOST : address.getHostAddress();
StringgetMachineHostname()
get Machine Hostname
try {
    return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
    return "unknown";
StringgetMyHostname()
get My Hostname
String hostName = null;
try {
    hostName = InetAddress.getLocalHost().getHostName();
} catch (final UnknownHostException e) {
    try {
        final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
        while (interfaces.hasMoreElements()) {
            final NetworkInterface nic = interfaces.nextElement();
...
ProxygetProxy(String host, String proxyType)
get Proxy
Proxy foundProxy = null;
try {
    URI uri = new URI(proxyType, "//" + host, null);
    List<Proxy> proxies = ProxySelector.getDefault().select(uri);
    if (proxies != null) {
        for (Proxy proxy : proxies) {
            if (proxy != Proxy.NO_PROXY) {
                foundProxy = proxy;
...
StringgetServerHost()
get Server Host
final String host = System.getProperty("node0", "localhost");
return toIPv6URLFormat(host);
StringgetShortHostName()
get the current host name
String hostname = null;
try {
    hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
    e.printStackTrace();
return hostname;
StringgetShortHostName()
get Short Host Name
String name = getHostName();
int i = name.indexOf('.');
if (i == -1)
    return name;
return name.substring(0, i);
StringgetShortHostname()
get Short Hostname
return getFullHostname().replaceAll("\\..*", "");