frenchbread / private-ip

Check if IP address is private.
MIT License
33 stars 16 forks source link

feat: regex for ipv6 #4

Closed vasco-santos closed 3 years ago

vasco-santos commented 3 years ago

This PR adds regex for ipv6 addresses per #3 . I needed to do a special validation for addresses started by 0 as they were not being considered ipv4. Open to improve this solution

This was based on https://en.m.wikipedia.org/wiki/Reserved_IP_addresses#IPv6

cc @sickcodes @frenchbread

sickcodes commented 3 years ago

I'll give it a test soon! Looks good.

sickcodes commented 3 years ago

What was wrong with netmask?

vasco-santos commented 3 years ago

netmask does not support ipv6 addresses

EDIT: https://github.com/rs/node-netmask/issues/8 I would like support on that, but I am not familiar with coffeescript at all

sickcodes commented 3 years ago
npm run test
168 passed

Also tested the inverse of the test and 168 failed which is good.

Here's upstream of is-ip anyway: https://github.com/sindresorhus/ip-regex/blob/master/index.js

@frenchbread

frenchbread commented 3 years ago

Thanks for the PR! Good work. Works fine for me as well.

Could you please update the package version also, @vasco-santos & I'll merge it.

vasco-santos commented 3 years ago

Sure, added a new commit for the release.

frenchbread commented 3 years ago

@vasco-santos Cool, thanks!

frenchbread commented 3 years ago

Sorry, @vasco-santos, for rising these points after code has been merged. I am just wondering for future improvements.