IPV6范围为CIDR

时间:2018-04-11 15:24:38

标签: get range ipv6 cidr

我怎样才能编写带有IPV6开始和结束ip地址的Java程序,并在String中给出可能的CIDR列表我有参考  这[[{3}}。但它只适用于IPV4我也需要IPV6。

1 个答案:

答案 0 :(得分:0)

open-source IPAddress Java library可以为您做到这一点。免责声明:我是IPAddress库的项目经理。

以下是执行此操作的示例代码:

world = x_range, y_range =  ((-18706892.5544, 21289852.6142), (-7631472.9040, 12797393.0236))

plot_width  = int(950)
plot_height = int(plot_width//1.2)

def base_plot(tools='pan,wheel_zoom,save,reset',plot_width=plot_width, 
plot_height=plot_height, **plot_args):
p = figure(tools=tools, plot_width=plot_width, plot_height=plot_height,
    x_range=x_range, y_range=y_range, outline_line_color=None,
    min_border=0, min_border_left=0, min_border_right=0,
    min_border_top=0, min_border_bottom=0, **plot_args)

p.axis.visible = False
p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None
return p

options = dict(line_color=None, fill_color='blue', size=1.5, alpha=0.25)

background = "black"
export = partial(export_image, export_path="export", background=background)
cm = partial(colormap_select, reverse=(background=="white"))

def create_image(x_range, y_range, w=plot_width, h=plot_height):
    cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)
    agg = cvs.points(df, 'xWeb', 'yWeb')

    magma = ['#3B0F6F', '#8C2980', '#DD4968', '#FD9F6C', '#FBFCBF']

    img = tf.shade(agg, cmap=magma, how='eq_hist') # how='linear', 'log', 'eq_hist'
    return tf.dynspread(img, threshold=.05, max_px=15)

p = base_plot()
p.add_tile("WMS service")

#used to export image (without the WMS)
export(create_image(*world),"TweetGeos")

#call interactive image 
InteractiveImage(p, create_image)

该代码实际上对IPv6和IPv4均相同。由于您指定了IPv6,因此下面是一个IPv6示例:

Auth.auth().currentUser?.reload(completion: { (error) in
    guard error == nil else {
        // handle error
        print(error!.localizedDescription)
        return
    }

    // your code below
    if (Auth.auth().currentUser?.isEmailVerified)! {
        // present another vc
    } else {
        print("not verified yet") //Always prints that
    }
})

输出为:

static void toPrefixBlocks(String str1, String str2) {
    IPAddressString string1 = new IPAddressString(str1);
    IPAddressString string2 = new IPAddressString(str2);
    IPAddress one = string1.getAddress(), two = string2.getAddress();
    IPAddressSeqRange range = one.toSequentialRange(two);
    System.out.println("starting with range " + range);
    IPAddress blocks[] = range.spanWithPrefixBlocks();
    System.out.println("prefix blocks are " + Arrays.asList(blocks));
}