/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2011-2016 Incapture Technologies LLC
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package rapture.util;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;

import org.apache.log4j.Logger;

/**
 * Utility around networks
 * 
 * @author amkimian
 * 
 */
public class NetworkUtil {

    private static final Logger log = Logger.getLogger(NetworkUtil.class);

    private NetworkUtil() {

    }

    public static String getServerIP() {
        try {
            return InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            log.error("Unable to get the IP address of this machine", e);
            return null;
        }
    }

    /**
     * Get the IP address of the local machine, but only if it's a site local address, not the public internet facing address. This is usually a class-C type
     * address and allows access from within a network or subnet, for example.
     * 
     * @return
     */
    public static String getSiteLocalServerIP() {
        Enumeration<NetworkInterface> nics;
        try {
            nics = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
            log.error("Unable to access network interfaces on this machine", e);
            return null;
        }
        while (nics.hasMoreElements()) {
            NetworkInterface nic = nics.nextElement();
            if (log.isDebugEnabled()) {
                log.debug("Processing nic: " + nic.getName() + ":" + nic.getDisplayName());
            }
            Enumeration<InetAddress> addrs = nic.getInetAddresses();
            while (addrs.hasMoreElements()) {
                InetAddress addr = addrs.nextElement();
                log.debug("IP addr is: " + addr.getHostAddress());
                if (addr.isSiteLocalAddress()) {
                    return addr.getHostAddress();
                }
            }
        }
        return null;
    }

    public static String getServerName() {
        try {
            return InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            log.error("Unable to get hostname of this machine", e);
            return null;
        }
    }
}

@@ -2983,16 +2983,46 @@
 ddress()
+ %7C%7C (addr.isLoopbackAddress())
 ) %7B%0A    

handle loopback address