Closed YooLin closed 10 months ago
<dependency>
<groupId>com.github.seancfoley</groupId>
<artifactId>ipaddress</artifactId>
<version>5.4.0</version>
</dependency>
after read #114 .Using the following method got me what I wanted.
String ip = "157.0.50.55/11";
IPAddress ipAddress = new IPAddressString(ip).getAddress().toPrefixBlock();
System.out.println("lower = " + ipAddress.getLower().toSubnetString());
System.out.println("upper = " + ipAddress.getUpper().toSubnetString());
lower = 157.0.0.0
upper = 157.31.255.255
to drop the prefix length from the resulting lower and upper, you can also do:
String ip = "157.0.50.55/11";
IPAddress ipAddress = new IPAddressString(ip).getAddress().toPrefixBlock().withoutPrefixLength();
System.out.println("lower = " + ipAddress.getLower());
System.out.println("upper = " + ipAddress.getUpper());
157.0.50.55/11
thanks a lot! that was very helpful for me.
print
expect
Is this a bug?