Java Utililty Methods Host Address Get

List of utility methods to do Host Address Get

Description

The list of methods to do Host Address Get are organized into topic(s).

Method

StringgetHostName(String address)
get Host Name
try {
    int i = address.indexOf(':');
    if (i > -1) {
        address = address.substring(0, i);
    InetAddress inetAddress = InetAddress.getByName(address);
    if (inetAddress != null) {
        String hostname = inetAddress.getHostName();
...
StringgetHostName(String address)
get Host Name
try {
    int i = address.indexOf(':');
    if (i > -1) {
        address = address.substring(0, i);
    String hostname = hostNameCache.get(address);
    if (hostname != null && hostname.length() > 0) {
        return hostname;
...
StringgetHostName(String localAddress)
Get the host name of a local address, if available.
try {
    InetAddress addr = InetAddress.getByName(localAddress);
    return addr.getHostName();
} catch (Exception e) {
    return "unknown";
StringgetHostnameOrAddress()
Get the hostname or IP address.
try {
    return InetAddress.getLocalHost().getCanonicalHostName();
} catch (UnknownHostException ignored) {
    try {
        return getHostAddress();
    } catch (Exception e) {
        return null;
StringgetHostnameOrAddress()
get Hostname Or Address
try {
    final InetAddress addr = InetAddress.getLocalHost();
    return addr.getHostName();
} catch (UnknownHostException e) {
    try {
        Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
        if (interfaces == null) {
            return "";
...
StringgetHostNameOrAddress(String host)
get Host Name Or Address
String hostname = host;
try {
    InetAddress ia = InetAddress.getByName(host);
    if (ia != null)
        hostname = ia.getHostName();
} catch (UnknownHostException uhe) {
return hostname;
...