- java.lang.Object
-
- com.github.f4b6a3.uuid.util.internal.NetworkUtil
-
public final class NetworkUtil extends Object
Utility that returns HOSTNAME, MAC and IP.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetMachineString()Returns a string containing host name, MAC and IP.static Stringhostname()Returns the host name if found.static Stringip(NetworkInterface nic)Returns the IP address if found.static Stringmac(NetworkInterface nic)Returns the MAC address if found.static NetworkInterfacenic()Returns a network interface.
-
-
-
Method Detail
-
hostname
public static String hostname()
Returns the 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()} (the hard way);- Returns:
- a string
-
mac
public static String mac(NetworkInterface nic)
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(NetworkInterface nic)
Returns the IP address if found. Output format: "0.0.0.0" (if IPv4)- Returns:
- a string
-
getMachineString
public static String getMachineString()
Returns a string containing host name, MAC and IP. Output format: "hostname123 11-22-33-44-55-66 123.123.123.123"- Returns:
- a string
-
nic
public static NetworkInterface nic()
Returns a network interface. It tries to return the network interface associated to the host name. If that network interface is not found, it tries to return the first network interface that satisfies these conditions: - it is up and running; - it is not loopback; - it is not virtual; - it has a hardware address. If no acceptable network interface is found, it returns null.- Returns:
- a network interface.
-
-