beaugunderson / ip-address

💻 a library for parsing and manipulating IPv4 and IPv6 addresses in JavaScript
http://ip-address.js.org/
MIT License
525 stars 71 forks source link

Offsetting addresses #118

Open napei opened 3 years ago

napei commented 3 years ago

So found this library. Great job 👍

I would make a PR but I'm swamped at the moment, but in terms of a useful addition.

nextNetwork or nextSubnet which would return the address or subnet representing the next available address, i.e. the address after the broadcast address. Useful for VLSM/CIDR calculation where you want to get the next address. Essentially taking the broadcast address and adding one to it.

or

offsetAddress or something similar. Give it a positive or negative integer n, and return an address which is n addresses away from that ip. Same as above but a more general case. Not sure how to handle the case of overflowing a specified subnet, however, maybe that's not a problem. Maybe even a chainable method like .add() or .sub()

Essentially mathematical operations on ip addresses. Can be useful for address allocation and such also, where you want to iterate through the addresses in a subnet and do something with them.