Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for IPv6 in isIPRange(str) #1567

Closed
AnandChowdhary opened this issue Jan 1, 2021 · 3 comments
Closed

Add support for IPv6 in isIPRange(str) #1567

AnandChowdhary opened this issue Jan 1, 2021 · 3 comments
Labels

Comments

@AnandChowdhary
Copy link

Describe the bug
Currently, the isIPRange() method only supports IPv4 addresses. It should be extended to support IPv6 addresses as well.

Examples

isIPRange("192.0.2.0/24") // IPv4 CIDR is `true`
isIPRange("2001:db8::/32") // IPv6 CIDR is `false`

Additional context

@bakyazi
Copy link

bakyazi commented Jan 1, 2021

I suppose "isIPRange" check the string before '/' is valid IP or not. Maybe you should use valid ipv6 instead of "2001:db8::"

edit: sorry i've checked the code here the return statement of isIPRange

return isIP(parts[0], 4) && parts[1] <= 32 && parts[1] >= 0;

so it validate only IPv4. It may be rewritten as

return (isIP(parts[0], 4) && parts[1] <= 32 && parts[1] >= 0) || (isIP(parts[0],6) && parts[1] <= 64 && parts[1] >= 0);

You can open PR.

@bakyazi bakyazi mentioned this issue Jan 1, 2021
3 tasks
@bakyazi
Copy link

bakyazi commented Jan 1, 2021

@AnandChowdhary I opened a PR. after they review, it can be merged

@neilime
Copy link
Contributor

neilime commented Apr 17, 2021

This PR should resolve this issue: #1594

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants