ipaddressrange
ipaddressrange copied to clipboard
Cidr subnets not working
Greetings,
Calculating the Cidr subnets from an IP range doesn't seem to work. Error: 192.168.0.0-192.168.0.254 is not a CIDR Subnet.
// Calculates Cidr subnets var rangeI = IPAddressRange.Parse("192.168.0.0-192.168.0.254"); rangeI.ToCidrString(); // is 192.168.0.0/24
The CIDR range "192.168.0.0/24" means the IPv4 address range from "192.168.0.0" to "192.168.0.255" (not "192.168.0.254").
The CIDR range "192.168.0.0/24" contains the range "192.168.0.0-192.168.0.254", but these are not equivalent.
ToCidrString()
returns the CIDR expression what is equivalent to represent the IPAddressRange
object it self.
This is by design.
Why did you think the IPv4 range "192.168.0.0-192.168.0.254" will fit valid CIDR range expression?
Perhaps I misunderstood what the actual method was for. I thought it was to find a subnet of a network range and return the CIDR notation. For example: 192.168.0.1 to 192.168.15.254 would be 192.168.0.0/20.
BigPacket, this IpAddressRange repo is great, but it doesn't find a list of CIDR subnets from an address range (as far as I can tell). I had to find something else for that. I ended up finding this sample code that shows how to calculate that: https://blog.ip2location.com/knowledge-base/how-to-convert-ip-address-range-into-cidr/
Cool, thank you.
From: Torrents [mailto:[email protected]] Sent: Wednesday, February 26, 2020 7:19 PM To: jsakamoto/ipaddressrange [email protected] Cc: BigPacket [email protected]; Author [email protected] Subject: Re: [jsakamoto/ipaddressrange] Cidr subnets not working (#58)
BigPacket, this IpAddressRange repo is great, but it doesn't find a list of CIDR subnets from an address range. I had to find something else for that. I ended up finding this sample code that shows how to calculate that: https://blog.ip2location.com/knowledge-base/how-to-convert-ip-address-range-into-cidr/
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jsakamoto/ipaddressrange/issues/58?email_source=notifications&email_token=AGAONS6QWBZPF5QSQF6KCELRE4BGZA5CNFSM4KZ4PET2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENCM3LQ#issuecomment-591711662 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AGAONS52KGII4MDDTKV3LWTRE4BGZANCNFSM4KZ4PETQ . https://github.com/notifications/beacon/AGAONS2SV5AAZYRRJDQZSATRE4BGZA5CNFSM4KZ4PET2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENCM3LQ.gif
Hi @jsakamoto I've tried your example directly here, it throws a format exception.
Hi @ekondur, I think you misunderstood @jsakamoto's response in this thread. He specifically agreed that "192.168.0.0 - 192.168.0.254" is not equivalent to a CIDR range, and will throw an exception.
However "192.168.0.0 - 192.168.0.255" is equivalent to the CIDR range 192.168.0.0/24.