Class NetworkUtil


  • public final class NetworkUtil
    extends Object
    Utility that returns host name, MAC and IP.
    • Method Detail

      • hostname

        public static String hostname()
        Returns the MAC host name if found. Sequence of HOSTNAME search: 1. Try to find the HOSTNAME variable in LINUX environment; 2. Try to find the COMPUTERNAME variable in WINDOWS environment; 3. Try to find the host name by calling {code InetAddress.getLocalHost().getHostName()};
        Returns:
        a string
      • mac

        public static String mac()
        Returns the MAC address if found. Output format: "00-00-00-00-00-00" (in upper case)
        Returns:
        a string
      • ip

        public static String ip()
        Returns the IP address if found. Output format: "0.0.0.0" (if IPv4)
        Returns:
        a string
      • nic

        public static NetworkInterface nic()
        Returns a network interface. It returns the first network interface that satisfies these conditions: - it is not loop back; - it has MAC address; - it has IP address.
        Returns:
        a network interface.