Example usage for java.net InetAddress getHostAddress

List of usage examples for java.net InetAddress getHostAddress

Introduction

In this page you can find the example usage for java.net InetAddress getHostAddress.

Prototype

public String getHostAddress() 

Source Link

Document

Returns the IP address string in textual presentation.

Usage

From source file:com.l2jfree.loginserver.manager.BanManager.java

public Entry<SubNet, BanInfo> getInfo(InetAddress address) {
    for (Map.Entry<SubNet, BanInfo> _bannedIP : _bannedIps.entrySet()) {
        SubNet net = _bannedIP.getKey();
        if (net.isInSubnet(address.getHostAddress()))
            return _bannedIP;
    }//from   ww  w .  ja  v a 2 s . com
    return null;
}

From source file:com.kyne.webby.rtk.web.Connection.java

private void logUser(final InetAddress inetAddress) {
    this.webServer.getConnectedAdmins().put(inetAddress.getHostAddress(), new Date());
}

From source file:wuit.crawler.CrawlerHtml.java

private void getUrlInfo(DSCrawlerUrl info) {
    try {//from w  w  w. j av  a  2s .c  o  m
        //            System.out.println("getUrlInfo : " + info.url);

        URL _url = new URL(info.url);
        info.dns = _url.getHost() + "";
        info.path = _url.getPath();
        info.file = _url.getProtocol();
        if (!info.url.equals("") && info.url != null) {
            InetAddress a = InetAddress.getByName(_url.getHost());
            if (a != null)
                info.IP = a.getHostAddress();
        }
        /*        } catch (MalformedURLException ex) {
                    Logger.getLogger(CrawlerHtml.class.getName()).log(Level.SEVERE, null, ex);
                } catch (UnknownHostException ex) {
                    Logger.getLogger(CrawlerHtml.class.getName()).log(Level.SEVERE, null, ex);*/
    } catch (Exception e) {
        System.out.println(" crawlerHtml   " + e.getMessage());
    }
}

From source file:com.l2jfree.loginserver.manager.BanManager.java

/**
 * Remove the specified address from the ban list
 * @param address The address to be removed from the ban list
 * @return true if the ban was removed, false if there was no ban for this IP
 *//*from w w w . j  a va2  s .  com*/
public boolean removeBanForAddress(InetAddress address) {
    for (Map.Entry<SubNet, BanInfo> _bannedIP : _bannedIps.entrySet()) {
        SubNet net = _bannedIP.getKey();

        if (net.isInSubnet(address.getHostAddress()) && (net.getMask() == 0xffffffff))
            return _bannedIps.remove(net) != null;
    }

    return false;
}

From source file:io.tilt.minka.domain.NetworkShardIDImpl.java

private InetAddress findSiteAddress(final Config config) {
    InetAddress fallback = null;// ww  w. ja v a  2s .c o  m
    try {
        final String niName = config.getFollowerUseNetworkInterfase();
        logger.info("{}: Looking for configured network interfase: {}", getClass().getSimpleName(), niName);
        final Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
        while (nis.hasMoreElements()) {
            final NetworkInterface ni = nis.nextElement();
            if (niName.contains(ni.getName())) {
                logger.info("{}: Interfase found: {}, looking for a Site address..", getClass().getSimpleName(),
                        ni.getName());
                final Enumeration<InetAddress> ias = ni.getInetAddresses();
                while (ias.hasMoreElements()) {
                    final InetAddress ia = ias.nextElement();
                    if (ia.isSiteLocalAddress()) {
                        logger.info("{}: Host site address found: {}:{} with HostName {}",
                                getClass().getSimpleName(), ia.getHostAddress(), config.getBrokerServerPort(),
                                ia.getHostName());
                        return ia;
                    } else {
                        fallback = ia;
                        logger.warn("{}: Specified interfase: {} is not a site address!!, "
                                + "you should specify a non local-only valid interfase !! where's your lan?",
                                getClass().getSimpleName(), ia.getHostAddress());
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.error("{}: Cannot build shard id value with hostname", getClass().getSimpleName(), e);
    }
    logger.error("{}: Site network interfase not found !", getClass().getSimpleName());
    return fallback;
}

From source file:HTTPChunkLocator.java

/**
 * parses a chunk info part// w  ww .  j  ava2  s .co  m
 * <p/>
 * <pre>
 *  <chunk_list>
 *    <chunk offset="0" chunk_size="67108864">
 *      <map>
 *        <copy ip_addr="10.10.2.200" name="vistasn1" snid="1" vid="1" />
 *        <copy ip_addr="10.10.2.201" name="vistasn2" snid="2" vid="3" />
 *     </map>
 *    </chunk>
 *  </chunk_list>
 * </pre>
 */
private List<ChunkLocation> parseChunks(final XMLEventReader reader, final long fileSizeInBytes)
        throws XMLStreamException, IOException {
    long offset = -1;
    long length = -1;
    final List<ChunkLocation> locations = new ArrayList<ChunkLocation>(5);
    final List<StorageNodeInfo> sninfo = new ArrayList<StorageNodeInfo>();
    final List<Integer> volumeIds = new ArrayList<Integer>();
    while (reader.hasNext()) {
        final XMLEvent nextEvent = reader.nextEvent();
        if (!(nextEvent instanceof StartElement)) {
            continue;
        }
        final StartElement start = (StartElement) nextEvent;
        if (CHUNK_ID.equals(start.getName().getLocalPart())) {
            if (sninfo.size() > 0) {
                final ChunkInfo chunkInfo = new ChunkInfo(offset, length, volumeIds.toArray(new Integer[0]));
                locations.add(
                        new ChunkLocation(sninfo.toArray(new StorageNodeInfo[0]), chunkInfo, fileSizeInBytes));
                sninfo.clear();
                volumeIds.clear();
            }
            offset = Long.parseLong(get(start, Q_OFFSET));
            length = Long.parseLong(get(start, Q_CHUNK_SIZE));

        } else if (COPY_ID.equals(start.getName().getLocalPart())) {
            final InetAddress ip = InetAddress.getByName(get(start, Q_IP_ADDR));
            final int vid = Integer.parseInt(get(start, Q_VID));
            final String name = get(start, Q_NAME);
            sninfo.add(new StorageNodeInfo(name, ip.getHostAddress(), true, true));
            volumeIds.add(Integer.valueOf(vid));

        }
    }
    if (sninfo.size() > 0) {
        final ChunkInfo chunkInfo = new ChunkInfo(offset, length, volumeIds.toArray(new Integer[0]));
        locations.add(new ChunkLocation(sninfo.toArray(new StorageNodeInfo[0]), chunkInfo, fileSizeInBytes));
    }
    return locations;
}

From source file:com.kyne.webby.rtk.web.Connection.java

private boolean isUserLoggedIn(final InetAddress inetAddress) {
    return this.webServer.getConnectedAdmins().containsKey(inetAddress.getHostAddress());
}

From source file:com.nridge.connector.ws.con_ws.restlet.RestletApplication.java

/**
 * Returns a Restlet instance used to identify inbound requests for the
 * web service endpoints.//from  w  w  w .j  av  a  2s .c  o  m
 *
 * @return Restlet instance.
 */
@Override
public Restlet createInboundRoot() {
    Restlet restletRoot;
    Logger appLogger = mAppMgr.getLogger(this, "createInboundRoot");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    Context restletContext = getContext();
    Router restletRouter = new Router(restletContext);

    String propertyName = "restlet.host_names";
    String hostNames = mAppMgr.getString(propertyName);
    if (StringUtils.isEmpty(hostNames)) {
        try {
            InetAddress inetAddress = InetAddress.getLocalHost();

            routerAttachEndPoints(restletRouter, "localhost");
            routerAttachEndPoints(restletRouter, inetAddress.getHostName());
            routerAttachEndPoints(restletRouter, inetAddress.getHostAddress());
            routerAttachEndPoints(restletRouter, inetAddress.getCanonicalHostName());
        } catch (UnknownHostException e) {
            appLogger.error(e.getMessage(), e);
            routerAttachEndPoints(restletRouter, "localhost");
        }
    } else {
        if (mAppMgr.isPropertyMultiValue(propertyName)) {
            String[] hostNameList = mAppMgr.getStringArray(propertyName);
            for (String hostName : hostNameList)
                routerAttachEndPoints(restletRouter, hostName);
        }
    }

    RestletFilter restletFilter = new RestletFilter(mAppMgr, restletContext);
    propertyName = "restlet.allow_addresses";
    String allowAddresses = mAppMgr.getString(propertyName);
    if (StringUtils.isNotEmpty(allowAddresses)) {
        if (mAppMgr.isPropertyMultiValue(propertyName)) {
            String[] allowAddressList = mAppMgr.getStringArray(propertyName);
            for (String allowAddress : allowAddressList) {
                restletFilter.add(allowAddress);
                appLogger.debug("Filter Allow Address: " + allowAddress);
            }
        } else {
            restletFilter.add(allowAddresses);
            appLogger.debug("Filter Allow Address: " + allowAddresses);
        }
        restletFilter.setNext(restletRouter);
        restletRoot = restletFilter;
    } else
        restletRoot = restletRouter;

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);

    return restletRoot;
}

From source file:com.l2jfree.loginserver.manager.BanManager.java

public boolean isRestrictedAddress(InetAddress address) {
    for (Map.Entry<SubNet, BanInfo> _bannedIP : _restrictedIps.entrySet()) {
        SubNet net = _bannedIP.getKey();

        if (net != null && net.isInSubnet(address.getHostAddress())) {
            BanInfo bi = _bannedIP.getValue();
            if (bi != null)
                return true;
        }// w  w w  .j a  v a 2s.c om
    }
    return false;
}