Example usage for java.net InetAddress toString

List of usage examples for java.net InetAddress toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Converts this IP address to a String .

Usage

From source file:rtspproxy.filter.ipaddress.SimpleIpAddressProvider.java

public boolean isBlocked(InetAddress address) {
    boolean blocked = true; // by default the address is blocked
    String[] hostip = address.toString().split("/");
    String host = hostip[0];//from w w  w  .  j  av  a  2 s.c o  m
    String ip = hostip[1];

    for (IpAddressPattern rule : rules) {
        if (blocked && rule.getType() == Type.Deny)
            // Don't need to check, up to now this IP is already
            // blocked
            continue;

        if (rule.getPattern().matcher(ip).matches() || rule.getPattern().matcher(host).matches())
            // the address matches the pattern
            // check if it's allow or deny
            blocked = (rule.getType() == Type.Allow) ? false : true;
    }

    return blocked;
}

From source file:jnode.net.NetworkInterface.java

/**
 * Returns a string representation of the interface
 *//*from   w  w  w . j  a  va  2  s  .c o m*/
@SuppressWarnings("unchecked")
public String toString() {
    // FIXME: check if this is correct
    String result;
    String separator = System.getProperty("line.separator");

    result = "name: " + getDisplayName() + " (" + getName() + ") addresses:" + separator;

    for (Enumeration e = getInetAddresses(); e.hasMoreElements();) {
        InetAddress address = (InetAddress) e.nextElement();
        result += address.toString() + separator;
    }

    return result;
}

From source file:org.apache.ambari.servicemonitor.Monitor.java

/**
 * Add sysprops and env variables to the dump
 * @return/*  www. ja  v a  2  s  .  com*/
 */
@Override
public String dump() {
    StringBuilder dump = new StringBuilder();

    InetAddress hostname = MonitorUtils.getLocalHost();
    if (hostname != null) {
        dump.append("Hostname:").append(hostname.toString()).append("\n");
    } else {
        dump.append("Hostname/address unknown!\n");
    }

    //now locate and print the location of log4j so as to see what is going wrong.
    return dump.toString();
}

From source file:com.pidoco.juri.JURI.java

/**
 * Relies on implementation details of the InetAddress class, hopefully not changing. There is a test, of course.
 *//* w  w w  .ja  v a2s.  c  o m*/
protected static boolean checkIfAddressHasHostnameWithoutNameLookup(InetAddress address) {
    // Cannot check with getHostName or getCanonicalName because they can incur a name lookup and we want to avoid
    // blocking.
    // Remark: InetSocketAddress's unresolved and holder functionality not better suited.
    return !address.toString().startsWith("/");
}

From source file:org.starnub.starnubserver.connections.player.character.CharacterIP.java

/**
 * Constructor used in adding, removing or updating a object in the database table character_ip_log
 *
 * @param playerCharacter PlayerCharacter of the character that was seen with this ip
 * @param sessionIp InetAddress representing the IP Address
 *///w w w.  ja  va 2 s.  c  o  m
public CharacterIP(PlayerCharacter playerCharacter, InetAddress sessionIp, boolean createEntry) {
    this.playerCharacter = playerCharacter;
    this.sessionIpString = StringUtils.remove(sessionIp.toString(), "/");
    if (createEntry) {
        CHARACTER_IP_LOG_DB.createOrUpdate(this);
    }
}

From source file:org.mangelp.fakeSmtpWeb.httpServer.HttpServer.java

public HttpServer(InetAddress addr, int port) {
    super(addr != null ? addr.getHostName() : null, port);
    this.serverPort = port;
    this.serverAddr = addr != null ? addr.toString() : "";
}

From source file:org.kawanfw.file.servlet.KawanNotifier.java

/**
 * Notify the Host that a user has done a login - Done once in a server
 * session. <br>//from  w  ww .  ja v a2s  . com
 * This is done in this secured thread: the Server File Manager Servlet will
 * not wait and all thrown <code>Exceptions</code> are trapped
 */
public void run() {

    BufferedReader bufferedReader = null;

    try {

        if (!usernames.contains(username)) {
            usernames.add(username);

            // Increment the number of users
            usernameCpt++;

            InetAddress inetAddress = InetAddress.getLocalHost();

            String ip = inetAddress.toString();

            // Make IP address completely anonymous
            Sha1 sha1 = new Sha1();
            ip = sha1.getHexHash(ip.getBytes());

            String urlStr = "http://www.kawanfw.org/NotifyNew?ip=" + ip + "&user=" + usernameCpt + "&product="
                    + product;

            debug("urlStr: " + urlStr);

            URL url = new URL(urlStr);
            URLConnection urlConnection = url.openConnection();

            bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            String inputLine;
            while ((inputLine = bufferedReader.readLine()) != null) {
                debug(inputLine);
            }
        }

    } catch (Exception e) {
        if (DEBUG) {
            try {
                ServerLogger.getLogger().log(Level.WARNING,
                        Tag.PRODUCT_EXCEPTION_RAISED + " Notify Exception: " + e.toString());
            } catch (Exception e1) {
                e1.printStackTrace(System.out);
            }
        }
    } finally {
        IOUtils.closeQuietly(bufferedReader);
    }
}

From source file:com.adito.setup.forms.SystemInfoForm.java

/**
 * Get a list (as strings) of the nwrok interfaces that are available
 * on this host./*from   w w  w.j  a  v  a  2s. co m*/
 *   
 * TODO This should be the interfaces that Adito is using.
 *   
 * @return network interfaces
 */
public List getNetworkInterfaces() {
    Enumeration e = null;
    try {
        List niList = new ArrayList();
        e = NetworkInterface.getNetworkInterfaces();
        while (e.hasMoreElements()) {
            NetworkInterface netface = (NetworkInterface) e.nextElement();
            Enumeration e2 = netface.getInetAddresses();
            while (e2.hasMoreElements()) {
                InetAddress ip = (InetAddress) e2.nextElement();
                niList.add(netface.getName() + "=" + ip.toString());
            }
        }
        return niList;
    } catch (SocketException e1) {
        return new ArrayList();
    }
}

From source file:org.ecocean.ImageProcessor.java

public void run() {
    //        status = Status.INIT;

    if (StringUtils.isBlank(this.command)) {
        log.warn("Can't run processor due to empty command");
        return;//from ww  w.  j a  v a2  s  . c om
    }

    if (StringUtils.isBlank(this.imageSourcePath)) {
        log.warn("Can't run processor due to empty source path");
        return;
    }

    if (StringUtils.isBlank(this.imageTargetPath)) {
        log.warn("Can't run processor due to empty target path");
        return;
    }

    String comment = CommonConfiguration.getProperty("imageComment", this.context);
    if (comment == null)
        comment = "%year All rights reserved. | wildbook.org";
    String cname = ContextConfiguration.getNameForContext(this.context);
    if (cname != null)
        comment += " | " + cname;
    String maId = "unknown";
    String rotation = "";
    if (this.parentMA != null) {
        if (this.parentMA.getUUID() != null) {
            maId = this.parentMA.getUUID();
            comment += " | parent " + maId;
        } else {
            maId = this.parentMA.setHashCode();
            comment += " | parent hash " + maId; //a stretch, but maybe should never happen?
        }
        if (this.parentMA.hasLabel("rotate90")) {
            rotation = "-flip -transpose";
        } else if (this.parentMA.hasLabel("rotate180")) {
            rotation = "-flip -flop";
        } else if (this.parentMA.hasLabel("rotate270")) {
            rotation = "-flip -transverse";
        }
    }
    comment += " | v" + Long.toString(System.currentTimeMillis());
    try {
        InetAddress ip = InetAddress.getLocalHost();
        comment += ":" + ip.toString() + ":" + ip.getHostName();
    } catch (UnknownHostException e) {
    }

    int year = Calendar.getInstance().get(Calendar.YEAR);
    comment = comment.replaceAll("%year", Integer.toString(year));
    //TODO should we handle ' better? -- this also assumes command uses '%comment' quoting  :/
    comment = comment.replaceAll("'", "");

    String fullCommand;
    fullCommand = this.command.replaceAll("%width", Integer.toString(this.width))
            .replaceAll("%height", Integer.toString(this.height))
            //.replaceAll("%imagesource", this.imageSourcePath)
            //.replaceAll("%imagetarget", this.imageTargetPath)
            .replaceAll("%maId", maId).replaceAll("%additional", rotation).replaceAll("%arg", this.arg);

    //walk thru transform array and replace "tN" with transform[N]
    if (this.transform.length > 0) {
        for (int i = 0; i < this.transform.length; i++) {
            fullCommand = fullCommand.replaceAll("%t" + Integer.toString(i), Float.toString(this.transform[i]));
        }
    }

    String[] command = fullCommand.split("\\s+");

    //we have to do this *after* the split-on-space cuz files may have spaces!
    for (int i = 0; i < command.length; i++) {
        if (command[i].equals("%imagesource"))
            command[i] = this.imageSourcePath;
        if (command[i].equals("%imagetarget"))
            command[i] = this.imageTargetPath;
        //note this assumes comment stands alone. :/
        if (command[i].equals("%comment"))
            command[i] = comment;
        System.out.println("COMMAND[" + i + "] = (" + command[i] + ")");
    }
    //System.out.println("done run()");
    //System.out.println("command = " + Arrays.asList(command).toString());

    ProcessBuilder pb = new ProcessBuilder();
    pb.command(command);
    /*
            Map<String, String> env = pb.environment();
            env.put("LD_LIBRARY_PATH", "/home/jon/opencv2.4.7");
    */
    //System.out.println("before!");

    try {
        Process proc = pb.start();
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
        String line;
        while ((line = stdInput.readLine()) != null) {
            System.out.println(">>>> " + line);
        }
        while ((line = stdError.readLine()) != null) {
            System.out.println("!!!! " + line);
        }
        proc.waitFor();
        System.out.println("DONE?????");
        ////int returnCode = p.exitValue();
    } catch (Exception ioe) {
        log.error("Trouble running processor [" + command + "]", ioe);
    }
    System.out.println("RETURN");
}

From source file:com.predic8.membrane.core.transport.http.HttpServerHandler.java

private void updateThreadName(boolean fromConnection) {
    if (fromConnection) {
        StringBuilder sb = new StringBuilder();
        sb.append(HttpServerThreadFactory.DEFAULT_THREAD_NAME);
        sb.append(" ");
        InetAddress ia = sourceSocket.getInetAddress();
        if (ia != null)
            sb.append(ia.toString());
        sb.append(":");
        sb.append(sourceSocket.getPort());
        Thread.currentThread().setName(sb.toString());
    } else {/*w  w  w .ja  v a  2s. co m*/
        Thread.currentThread().setName(HttpServerThreadFactory.DEFAULT_THREAD_NAME);
    }
}