gpt4 book ai didi

Java 和 IP - 子网解析

转载 作者:行者123 更新时间:2023-12-01 04:10:50 34 4
gpt4 key购买 nike

java中有没有一种简单的方法可以从格式中获取IP范围

175.25.0.0/16

有点像175.25.0.0-175.25.255.255

最佳答案

public String getHostAddressRange(String netmaskNumeric) {

    int numberOfBits;
for (numberOfBits = 0; numberOfBits < 32; numberOfBits++) {

if ((netmaskNumeric << numberOfBits) == 0)
break;
}
Integer numberOfIPs = 0;
for (int n = 0; n < (32 - numberOfBits); n++) {

numberOfIPs = numberOfIPs << 1;
numberOfIPs = numberOfIPs | 0x01;

}

Integer baseIP = baseIPnumeric & netmaskNumeric;
String firstIP = convertNumericIpToSymbolic(baseIP + 1);
String lastIP = convertNumericIpToSymbolic(baseIP + numberOfIPs - 1);
return firstIP + " - " + lastIP;
}

关于Java 和 IP - 子网解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19945499/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com