Java InetAddress increment(InetAddress address)

Here you can find the source of increment(InetAddress address)

Description

Increments an IP address by 1.

License

GNU General Public License

Declaration

public static InetAddress increment(InetAddress address) 

Method Source Code

//package com.java2s;
/**/*from  w w w .  j  av a  2s. 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;

import java.net.UnknownHostException;

public class Main {
    /**
     * Increments an IP address by 1.
     */
    public static InetAddress increment(InetAddress address) {
        try {
            byte[] newAddress = address.getAddress();
            for (int i = newAddress.length - 1; i >= 0; i--) {
                if (++newAddress[i] != 0x00)
                    break;
            }
            return InetAddress.getByAddress(newAddress);
        } catch (UnknownHostException e) {
            // this exception is unexpected here
            assert false : e;
            return null;
        }
    }
}

Related

  1. formatAddress(InetAddress inet)
  2. formatHostAddress(final InetAddress localHost)
  3. greaterThan(InetAddress inetAddress1, InetAddress inetAddress2)
  4. hasIp(InetAddress ip)
  5. hasLocalScope(InetAddress addr)
  6. inetAddressCompare(final InetAddress address1, final InetAddress address2)
  7. inetAddressesComparator(final boolean sameHost)
  8. inetAddressesCompare(final InetAddress[] addresses1, final InetAddress[] addresses2)
  9. inetAddressFromThriftString(String ipAddress)