- java.lang.Object
-
- com.github.f4b6a3.uuid.util.internal.NetworkUtil
-
public final class NetworkUtil extends Object
Utility class that returns host name, 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:
- Try to find the HOSTNAME variable on LINUX environment;
- Try to find the COMPUTERNAME variable on WINDOWS environment;
- Try to find the host name by calling
InetAddress.getLocalHost().getHostName()(the expensive way); - If no host name is found, return
null.
- Returns:
- a string containing the host name
-
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 containing the MAC address
-
ip
public static String ip(NetworkInterface nic)
Returns the IP address if found.Output format: "0.0.0.0" (if IPv4)
- Returns:
- a string containing the IP address
-
getMachineString
public static String getMachineString()
Returns a string containing host name, MAC and IP.Output format: "hostname 11-11-11-11-11-11 222.222.222.222"
- Returns:
- a string containing the host name, MAC and IP
-
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.
-
-