All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.taccisum.swagger.configurer.util.NetUtils Maven / Gradle / Ivy

The newest version!
package com.github.taccisum.swagger.configurer.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author tac - [email protected]
 * @since 2019/2/12
 */
public abstract class NetUtils {
    private static String getHostNameForLinux() {
        try {
            return (InetAddress.getLocalHost()).getHostName();
        } catch (UnknownHostException uhe) {
            String host = uhe.getMessage(); // host = "hostname: hostname"
            if (host != null) {
                int colon = host.indexOf(':');
                if (colon > 0) {
                    return host.substring(0, colon);
                }
            }
            return "Unknown Host";
        }
    }

    public static String getHostName() {
        if (System.getenv("COMPUTERNAME") != null) {
            return System.getenv("COMPUTERNAME");
        } else {
            return getHostNameForLinux();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy