ip-address icon indicating copy to clipboard operation
ip-address copied to clipboard

Support for "edge-case" ip notations

Open StoneLabs opened this issue 4 years ago • 1 comments

Currently, there seem to be quite a lot of valid IPs that throw [AddressError]: Invalid IPv4 address.

var Address4 = require('ip-address').Address4;

// All of the following are rejected as invalid.
const topic = new Address4('127.1'); // equivalent to 127.0.0.1
const topic = new Address4('127.0.1'); // equivalent to 127.0.0.1
const topic = new Address4('192.168.36095'); // equivalent to 192.168.140.255 in CLASS B notation
const topic = new Address4('192.11046143');  // equivalent to 192.168.140.255 in CLASS C notation
const topic = new Address4('0xc0.0xa8.0x8c.0xff');  // equivalent to 192.168.140.255 in valid hex notation
const topic = new Address4('0300.0250.0214.0377');  // equivalent to 192.168.140.255 in valid oct notation (though some implementations ignore oct notation)
const topic = new Address4('0000000001.0000000002.0000000003.000000010');  // equivalent to 1.2.3.8 in valid oct notation (though some implementations ignore oct notation)

// Granted, these are all very absurd notations. However, all of these are valid ip's. you can verify this just pinging them.

image image

StoneLabs avatar Jul 20 '21 20:07 StoneLabs

I agree with you, we should successfully parse these notations… I may not have time to add them in the short term, but welcome any PRs if someone beats me to it!

On Tue, Jul 20, 2021 at 1:02 PM, Levy Ehrstein @.***> wrote:

Currently, there seem to be quite a lot of valid IPs that throw [AddressError]: Invalid IPv4 address.

var Address4 = require('ip-address').Address4; // All of the following are rejected as invalid.const topic = new Address4('127.1'); // equivalent to 127.0.0.1const topic = new Address4('127.0.1'); // equivalent to 127.0.0.1const topic = new Address4('192.168.36095'); // equivalent to 192.168.140.255 in CLASS B notationconst topic = new Address4('192.11046143'); // equivalent to 192.168.140.255 in CLASS C notationconst topic = new Address4('0xc0.0xa8.0x8c.0xff'); // equivalent to 192.168.140.255 in valid hex notationconst topic = new Address4('0300.0250.0214.0377'); // equivalent to 192.168.140.255 in valid oct notation (though some implementations ignore oct notation)const topic = new Address4('0000000001.0000000002.0000000003.000000010'); // equivalent to 1.2.3.8 in valid oct notation (though some implementations ignore oct notation) // Granted, these are all very absurd notations. However, all of these are valid ip's. you can verify this just pinging them.

[image: image] https://user-images.githubusercontent.com/19885942/126387617-a17cddf1-25e2-439d-8ed4-ac9b09c9f115.png [image: image] https://user-images.githubusercontent.com/19885942/126387640-660d0090-5105-4577-a333-12fbf2b42501.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/beaugunderson/ip-address/issues/142, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAPCX7FTJO5FI6PFRN3YWTTYXI6HANCNFSM5AWP2E5Q .

beaugunderson avatar Jul 20 '21 20:07 beaugunderson