Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ofarukcaki/ip-range
Check if the given IP address is in the provided range.
https://github.com/ofarukcaki/ip-range
Last synced: about 1 month ago
JSON representation
Check if the given IP address is in the provided range.
- Host: GitHub
- URL: https://github.com/ofarukcaki/ip-range
- Owner: ofarukcaki
- License: mit
- Created: 2020-04-25T20:31:33.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-26T08:49:26.000Z (almost 5 years ago)
- Last Synced: 2024-12-06T01:48:00.719Z (about 2 months ago)
- Language: TypeScript
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ip-range
Check if the given IP address is in the provided range.
## Install
```
npm i @ofarukcaki/ip-range
```## Usage
```javascript
const Iprange = require('@ofarukcaki/ip-range').default;const initialRanges = [
['0.0.0.1', '0.0.0.255'],
['123.123.0.0', '123.123.124.255'],
['66.0.0.0', '66.1.0.0'],
];/* Initialize a new range by providing an array of string arrays
* consists of start-end addresses of an IP.
* Don't pass a parameter if you don't want to initialize on creation
*/
const range = new Iprange(initialRanges);// add a new range
const newRange = ['192.0.0.1', '192.0.0.5'];
range.addRange(newRange);console.log(range.checkIP('123.123.1.0')); // true
console.log(range.checkIP('66.0.1.255')); // true
console.log(range.checkIP('192.0.0.0')); // false
```