jsakamoto / ipaddressrange

.NET Class Library for range of IP address, both IPv4 and IPv6.
Mozilla Public License 2.0
368 stars 71 forks source link

Add IEnumerable support to IPAddressRange #10

Closed gregmac closed 9 years ago

gregmac commented 9 years ago

Adds support for enumerating over the range.

foreach (var ip in IPAddressRange.Parse("192.168.0.1/23"))
{
    Console.WriteLine(ip);
}

One of the big benefits of this method is if you have a huge range with say, 16 million addresses: you can start using the results of the enumeration immediately, and at no time does there need to be all 16 million IPs allocated in-memory at once (unless you want that and do something like IPAddressRange.Parse("10.0.0.1/8").ToList() of course).

jsakamoto commented 9 years ago

Thank you for your contribution :+1: