ip-sub

1.7.1 • Public • Published

IP-sub

A small utility to manipulate prefixes. There are other possible solutions on npm, this was created mostly to prioritize performance.

It implements the following methods.

  • getIpAndCidr - if you provide "99.88.77.0/24" it returns ["99.88.77.0", 24]

  • isValidPrefix - it returns true/false

  • isValidIP - it returns true/false

  • sortByPrefix - it is a sorting function for an array or prefixes. It sorts the array based on the entire prefix.

  • sortByPrefixLength - it is a sorting function for an array or prefixes. It sorts the array based on the amount of bits of the netmask (from less specific to more specific).

  • expandIP - if you provide something like "127/8", you will receive "127.0.0.0/8". If you provide "2001:db8:123::", you will receive "2001:0db8:0123:0000:0000:0000:0000:0000". In case of IPv6, you can also do expandIP("2001:db8:123::", true) to obtain the expanded-shortened version "2001:db8:123:0:0:0:0:0" (without 0 padding).

  • isEqualIP - it checks for IP equality, it takes into account expansions and cases. E.g. "2001:db8:123::" is equal to "2001:DB8:123::0"

  • isEqualPrefix - same as above, but with prefixes

  • getAddressFamily - it returns 4 or 6 (integers)

  • toBinary - it returns the binary representation of the IP

  • fromBinary - it returns the decimal/hexadecimal representation of a binary IP (essentially, the opposite of the previous function)

  • applyNetmask - it applies the netmask. E.g., if you provide "99.88.77.0/24" you will get the binary representation of "99.88.77.0" truncated at 24 bits

  • isSubnet - you provide two prefixes and you will get true if the second one is subnet of the first one.

  • isSubnetBinary - same as above but directly with binary representation

  • cidrToRange - given a prefix in cidr notation, it returns the first and last ip address of the range.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.7.1140latest

Version History

VersionDownloads (Last 7 Days)Published
1.7.1140
1.7.031
1.6.26
1.6.10
1.6.00
1.5.8154
1.5.70
1.5.61
1.5.5129
1.5.46
1.5.30
1.5.20
1.5.10
1.5.01
1.4.00
1.3.964
1.3.80
1.3.70
1.3.60
1.3.51
1.3.40
1.3.30
1.3.211
1.3.10
1.3.00
1.2.21
1.2.10
1.2.01
1.1.20
1.1.10
1.1.00
1.0.280
1.0.271
1.0.260
1.0.250
1.0.240
1.0.230
1.0.220
1.0.211
1.0.200
1.0.191
1.0.180
1.0.171
1.0.160
1.0.150
1.0.141
1.0.120
1.0.110
1.0.100
1.0.90
1.0.81
1.0.71
1.0.60
1.0.50
1.0.41
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i ip-sub

Weekly Downloads

554

Version

1.7.1

License

MIT

Unpacked Size

24.7 kB

Total Files

4

Last publish

Collaborators

  • maxcam