seancfoley / IPAddress

Java library for handling IP addresses and subnets, both IPv4 and IPv6
https://seancfoley.github.io/IPAddress/
Apache License 2.0
466 stars 63 forks source link

Unexpected address returned when pass integer to IPAddressString #100

Closed anthais closed 1 year ago

anthais commented 1 year ago

My code:

IPAddressString ipAddressString = new IPAddressString("1111111");   
System.out.println(ipAddressString.getAddress());
// output: 0.16.244.71

I know this can be the int format of IPv4

IPAddressString ipAddressString = new IPAddressString("1111111");
System.out.println(ipAddressString.getAddress().toIPv4().intValue());
// output: 1111111

I want IPAddressString only accept IPv4, IPv6 or CIDR. How can I do it?

seancfoley commented 1 year ago

see https://github.com/seancfoley/IPAddress/issues/94 or https://seancfoley.github.io/IPAddress/ipaddress.html#address-or-host-name-validation-options