Java InetAddress greaterThan(InetAddress inetAddress1, InetAddress inetAddress2)

Here you can find the source of greaterThan(InetAddress inetAddress1, InetAddress inetAddress2)

Description

Compares two IP addresses.

License

GNU General Public License

Return

true in case inetAddress1 is greater than inetAddress2

Declaration

public static boolean greaterThan(InetAddress inetAddress1, InetAddress inetAddress2) 

Method Source Code

//package com.java2s;
/**//ww w .j a va  2 s  .com
 * This file is a part of Angry IP Scanner source code,
 * see http://www.angryip.org/ for more information.
 * Licensed under GPLv2.
 */

import java.net.InetAddress;

public class Main {
    /**
     * Compares two IP addresses.
     * @return true in case inetAddress1 is greater than inetAddress2
     */
    public static boolean greaterThan(InetAddress inetAddress1, InetAddress inetAddress2) {
        byte[] address1 = inetAddress1.getAddress();
        byte[] address2 = inetAddress2.getAddress();
        for (int i = 0; i < address1.length; i++) {
            if ((address1[i] & 0xFF) > (address2[i] & 0xFF))
                return true;
            else if ((address1[i] & 0xFF) < (address2[i] & 0xFF))
                break;
        }
        return false;
    }
}

Related

  1. findUnusedPort(InetAddress address, int from, int to)
  2. findUnusedPort(InetAddress address, int low, int high)
  3. formatAddress(InetAddress address, int port, Context cx, Scriptable scope)
  4. formatAddress(InetAddress inet)
  5. formatHostAddress(final InetAddress localHost)
  6. hasIp(InetAddress ip)
  7. hasLocalScope(InetAddress addr)
  8. increment(InetAddress address)
  9. inetAddressCompare(final InetAddress address1, final InetAddress address2)