集册 Java实例教程 获取子网络地址范围的字符串

获取子网络地址范围的字符串

欢马劈雪     最近更新时间:2020-01-02 10:19:05

545
获取子网络地址范围的字符串
/** 时 代 J a v a 公 众 号 - N o w J a v  a . c o m 提供 **/

//package com.nowjava;


import java.util.ArrayList;


import java.util.List;


public class Main {

    public static List<String> getStringOfSubNetworkAddressRanges(

            byte[][] addressRange) {

        List<String> addressRangeList = new ArrayList<String>();

        for (int i = 0; i < addressRange[0].length; i++) {

            if (i == 0) {

                addressRangeList.add(byteToString(addressRange[0][i]) + "-"

                        + byteToString(addressRange[1][i]));

            } else {

                for (int j = 0; j < addressRangeList.size(); j++) {

                    addressRangeList.set(j, "." + addressRangeList.get(j));

                }// from NowJava.com

                if (addressRange[0][i] == addressRange[1][i]) {

                    for (int j = 0; j < addressRangeList.size(); j++) {

                        addressRangeList.set(j,

                                byteToString(addressRange[0][i])

                                        + addressRangeList.get(j));

                    }

                } else {

                    int mapAddNumber = addressRange[1][i]

                            - addressRange[0][i];

                    int addressRangeListSize = addressRangeList.size();

                    for (int j = 0; j < addressRangeListSize; j++) {

                        String address = addressRangeList.get(j);

                        addressRangeList.set(j,

                                byteToString(addressRange[0][i]) + address);

                        for (int k = 1; k <= mapAddNumber; k++) {

                            addressRangeList

                                    .add(byteToString((byte) (addressR
展开阅读全文