inetaddress increment java

Solutions on MaxInterview for inetaddress increment java by the best coders in the world

showing results for - "inetaddress increment java"
Violeta
10 Nov 2019
1//package com.java2s;
2/**/*from  w w w .  j  av a  2s. com*/
3 * This file is a part of Angry IP Scanner source code,
4 * see http://www.angryip.org/ for more information.
5 * Licensed under GPLv2.
6 */
7
8import java.net.InetAddress;
9
10import java.net.UnknownHostException;
11
12public class Main {
13    /**
14     * Increments an IP address by 1.
15     */
16    public static InetAddress increment(InetAddress address) {
17        try {
18            byte[] newAddress = address.getAddress();
19            for (int i = newAddress.length - 1; i >= 0; i--) {
20                if (++newAddress[i] != 0x00)
21                    break;
22            }
23            return InetAddress.getByAddress(newAddress);
24        } catch (UnknownHostException e) {
25            // this exception is unexpected here
26            assert false : e;
27            return null;
28        }
29    }
30}
31
similar questions
queries leading to this page
inetaddress increment java