You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const Address4 = require('ip-address').Address4;
const address = new Address4('47.227.219.97/16');
console.log(address.isValid());
outputs true
but should false, like python's similar library
Python 3.5.6 (default, Nov 13 2018, 08:43:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipaddress
>>> ipaddress.ip_network('47.227.219.97/24')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/alt/python35/lib64/python3.5/ipaddress.py", line 74, in ip_network
return IPv4Network(address, strict)
File "/opt/alt/python35/lib64/python3.5/ipaddress.py", line 1537, in __init__
raise ValueError('%s has host bits set' % self)
ValueError: 47.227.219.97/24 has host bits set
Activity
asergeyev commentedon Apr 6, 2021
I think it's confusion on your part between IP inside of subnet and actual sub network address.
Here is startAddress() doc fragment:
The first address in the range given by this address' subnet. Often referred to as the Network Address.So if you'd like to check whether given IP is a valid network cidr you perhaps should compare startAddress() and correctForm().
Overall this lib's constructor behaves close to Python's
only keeping original IP around (which Python's
ipaddressdoes not)Clarify isValid() accepts CIDRs with host bits set (#81)
beaugunderson commentedon May 1, 2026
improved the docs via 98927be to make this clearer 👍