Java Local Host Get isLocalHostNameInList(String[] hostList)

Here you can find the source of isLocalHostNameInList(String[] hostList)

Description

is Local Host Name In List

License

Open Source License

Declaration

static public boolean isLocalHostNameInList(String[] hostList) 

Method Source Code

//package com.java2s;
/**/*  www .  j av a  2s  .c  om*/
 * Logback: the reliable, generic, fast and flexible logging framework.
 * Copyright (C) 1999-2013, QOS.ch. All rights reserved.
 *
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *
 *   or (per the licensee's choosing)
 *
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation.
 */

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

public class Main {
    static public boolean isLocalHostNameInList(String[] hostList) {
        String localHostName = getLocalHostName();
        if (localHostName == null) {
            return false;
        }
        for (String host : hostList) {
            if (host.equalsIgnoreCase(localHostName)) {
                return true;
            }
        }
        return false;
    }

    static public String getLocalHostName() {
        InetAddress localhostIA;
        try {
            localhostIA = InetAddress.getLocalHost();
            return localhostIA.getHostName();
        } catch (UnknownHostException e) {
            return null;
        }
    }
}

Related

  1. isLocalHost(String address)
  2. isLocalHost(String h1)
  3. isLocalhost(String host)
  4. isLocalhost(String hostname)
  5. isLocalhost(String someHost)