public final class NetworkUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
getMachineString()
Returns a string containing host name, MAC and IP.
|
static String |
hostname()
Returns the host name if found.
|
static String |
ip(NetworkInterface nic)
Returns the IP address if found.
|
static String |
mac(NetworkInterface nic)
Returns the MAC address if found.
|
static NetworkInterface |
nic()
Returns a network interface.
|
public static String hostname()
Sequence of HOSTNAME search:
InetAddress.getLocalHost().getHostName() (the expensive way);
null.
public static String mac(NetworkInterface nic)
Output format: "00-00-00-00-00-00" (in upper case)
nic - a network interfacepublic static String ip(NetworkInterface nic)
Output format: "0.0.0.0" (if IPv4)
nic - a network interfacepublic static String getMachineString()
Output format: "hostname 11-11-11-11-11-11 222.222.222.222"
public static NetworkInterface nic()
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:
If no acceptable network interface is found, it returns null.
Copyright © 2024. All rights reserved.