https://github.com/cloudnode-pro/ip
IP address utility
https://github.com/cloudnode-pro/ip
cidr ip ipcalc ipv4 ipv6 net netmask network subnet
Last synced: about 1 month ago
JSON representation
IP address utility
- Host: GitHub
- URL: https://github.com/cloudnode-pro/ip
- Owner: cloudnode-pro
- License: lgpl-3.0
- Created: 2024-11-01T17:10:04.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-27T09:40:53.000Z (over 1 year ago)
- Last Synced: 2024-11-27T10:31:40.273Z (over 1 year ago)
- Topics: cidr, ip, ipcalc, ipv4, ipv6, net, netmask, network, subnet
- Language: TypeScript
- Homepage:
- Size: 144 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# @cldn/ip
[](https://ip.cldn.pro)
[](https://github.com/cloudnode-pro/ip)
[](https://www.npmjs.com/package/@cldn/ip)
[](https://www.npmjs.com/package/@cldn/ip)
[](https://github.com/cloudnode-pro/ip/blob/master/COPYING)
[](https://github.com/cloudnode-pro/ip/actions/workflows/ci.yml)

A modern, object-oriented TypeScript library for representing and performing arithmetic on IP addresses and subnets.
[**Documentation — API Reference**](https://ip.cldn.pro)
## Usage
### Node.js
Install with `npm`:
```sh
npm install @cldn/ip
```
Import and use:
```ts
import {IPv4, IPv6, Subnet} from "@cldn/ip";
```
### Deno
Import the package from npm using the standard prefix:
```ts
import {IPv4, IPv6, Subnet} from "npm:@cldn/ip";
```
### Browsers
For browser usage, it is recommended to use a bundler like [Vite](https://vitejs.dev/),
or [Webpack](https://webpack.js.org/). If you are using a bundler, follow the same usage as for Node.js.
Alternatively, you can import the library as
a [JavaScript module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
from [ESM>CDN](https://esm.sh/):
```html
import {IPv4, IPv6, Subnet} from "https://esm.sh/@cldn/ip";
```
## Features
- Object-oriented representation of IPv4 and IPv6 addresses, and subnets.
- Comprehensive subnet arithmetic operations (e.g., containment, splitting, merging).
- Support for CIDR notation for defining and parsing subnets.
- Easy definition and manipulation of networks and collections of subnets.
- Support for IPv4-mapped IPv6 addresses.
- Fully documented, fully typed, and thoroughly tested with 100% coverage.
- Zero dependencies; compatible with frontend and backend environments without requiring polyfills.
## Example
```ts
import {IPv4, Subnet} from "@cldn/ip";
// Parse IPv4 address
const ip = IPv4.fromString("213.0.113.42");
// Or use IPAddress.fromString("213.0.113.42") to parse either IPv4 or IPv6
// Create subnet from CIDR notation
const subnet = Subnet.fromCIDR("213.0.113.0/24");
// Check if IP is within subnet
console.log(subnet.contains(ip)); // true
```
## Contact
For bugs, or feature requests, please use [GitHub Issues](https://github.com/cloudnode-pro/ip/issues).
For real-time chat or community discussions, join our Matrix
space: [#community\:cloudnode.pro](https://matrix.to/#/%23community:cloudnode.pro).
## Licence
Copyright © 2024–2025 Cloudnode OÜ.
This project is licensed under the terms of the [LGPL-3.0](https://github.com/cloudnode-pro/ip/blob/master/COPYING) licence.