Java Local Address Check isLoopbackAddress(String address)

Here you can find the source of isLoopbackAddress(String address)

Description

Checks if the specified address is a loopback address.

License

Open Source License

Parameter

Parameter Description
address address to check

Return

true if the address is a loopback one

Declaration

public static boolean isLoopbackAddress(String address) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {
    /**//from  ww w .  ja  v  a  2s . c  om
     * Checks if the specified address is a loopback address. This can be one of the following:
     * <ul>
     * <li>127.0.0.1</li>
     * <li>localhost</li>
     * <li>[::1]</li>
     * </ul>
     *
     * @param address address to check
     * @return true if the address is a loopback one
     */
    public static boolean isLoopbackAddress(String address) {
        try {
            InetAddress inetAddress = InetAddress.getByName(address);
            return inetAddress.isLoopbackAddress();
        } catch (UnknownHostException e) {
            return false;
        }
    }

    private static boolean isLoopbackAddress(InetAddress address) {
        return address.isLoopbackAddress();
    }
}

Related

  1. isLocalAddress(String address)
  2. isLocalAddress(String address)
  3. isLocalAddress(String address)
  4. isLocalAddress(String host)
  5. isLocalOrLoopback(String address)
  6. isMyAddress(String host)