jsakamoto / ipaddressrange

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

Cant parse example string #47

Closed gaazkam closed 6 years ago

gaazkam commented 6 years ago

Installed IPAddressRange v. 3.2.0 via NuGet

In the comments of your source file: https://github.com/jsakamoto/ipaddressrange/blob/master/IPAddressRange/IPAddressRange.cs

We see such a comment:

// Pattern 3. Begin end range: "169.258.0.0-169.258.0.255", "fe80::1%23-fe80::ff%23"

But Your lib fails to parse this very example string!

using NetTools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {    
            string ipstring = "169.258.0.0-169.258.0.255";
            IPAddressRange iprange = IPAddressRange.Parse(ipstring);
            Console.WriteLine(iprange.ToString());
            Console.ReadKey();
        }
    }
}

This throws! System.FormatException And TryParse returns false

jsakamoto commented 6 years ago

I'm sorry that the comments is invalid.

"192.258.0.0" is invalid IPv4 address, because a part of IPv4 address which is separated by dot(.) is representation of 8 bit value.
Therefore, the value 258 is invalid. (8 bit value can represent from 0 to 255.)

image

I fixed those comments just now.

https://github.com/jsakamoto/ipaddressrange/commit/f172285b853faa4e93f2c2bff0261611a42d4763#diff-84e5184cbe9467997f4166539b02496e

Thank you for your reporting! 👍