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

IPAddress .MapToIPv6() result doesn't parse. #37

Closed jonathh21 closed 6 years ago

jonathh21 commented 6 years ago

I have an IPAdress object containing "10.0.0.203" if i call MapToIpv6() I get "::ffff:10.0.0.203"

If I then try and pass that in to IPAddressRange.Parse i get an exception ""Unknown IP range string."".

Any clues?

jsakamoto commented 6 years ago

Oh, I have not ever consideration to IPv4 Mapped Address!

Give me a couple of days to solve this problem.

Thanks for your report. 👍

jonathh21 commented 6 years ago

Thank you. I am pretty new to the world of ipv6 and assumed we might as well stored the white listed addresses as ipv6. As you see it was using map from that we found them!

jsakamoto commented 6 years ago

I did it!

https://www.nuget.org/packages/IPAddressRange/3.1.0

jonathh21 commented 6 years ago

Thank you so very much. I'll roll this in today and look forward to trying it!

kimsey0 commented 3 years ago

(I hope it's OK that I revive this old issue instead of creating a new one, since the question is also related to mapped addresses.) @jsakamoto: I've noticed that IPv4 address ranges do not Contains IPv4 addresses mapped to IPv6. Would it make sense that they do? For example, what would you expect the value of IPAddressRange.Parse("10.0.0.0/24").Contains(new IPAddress(new byte[] { 10, 0, 0, 0 }).MapToIPv6()) to be?

jsakamoto commented 3 years ago

@kimsey0

what would you expect the value of IPAddressRange.Parse("10.0.0.0/24").Contains(new IPAddress(new byte[] { 10, 0, 0, 0 }).MapToIPv6()) to be?

I think it has to return false. Because an "IPv4-mapped IPv6 addresses" is IPv6, not IPv4, even if it contains IPv4 address part.

The responsibility of regularizing IP address family must be owned by developers, I think.

kimsey0 commented 3 years ago

That makes sense. Thank you!

jsakamoto commented 3 years ago

You are welcome :)