Java Host Check isInternalHostname(String host)

Here you can find the source of isInternalHostname(String host)

Description

Checks if a host name is internal

License

Open Source License

Parameter

Parameter Description
host the host name to check

Return

true: host name is internal
false: host name is external

Declaration

public static boolean isInternalHostname(String host) 

Method Source Code

//package com.java2s;
/*/*from w  ww .j ava  2s  .com*/
 * $Header: Util.java, 14-Jul-2005 03:27:51 luisantonioa Exp $
 * 
 * $Author: luisantonioa $ $Date: 14-Jul-2005 03:27:51 $ $Revision: 1 $ $Log:
 * Util.java,v $ Revision 1 14-Jul-2005 03:27:51 luisantonioa Added copyright
 * notice
 * 
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    /**
     * Checks if a host name is internal
     * 
     * @param host
     *    the host name to check
     * @return
     *    true: host name is internal<br>
     *    false: host name is external
     */
    public static boolean isInternalHostname(String host) {
        try {
            InetAddress addr = InetAddress.getByName(host);
            return addr.isSiteLocalAddress() || addr.isLoopbackAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related

  1. checkHost(String host)
  2. checkHost(String hostname)
  3. checkHostIsAvailable(String hostName)
  4. checkHostName(String hostName)
  5. isHostReachable(String host, int timeout)
  6. isLocal(final String hostName)
  7. isLocal(final String hostname)
  8. isThisMe(String hostname)
  9. normalizeHost(String host)