IP module for calculation (demical, subnet) / check bogon.
npm i @wnynya/ip
ESM
import IP from '@wnynya/ip';
const ip = new IP('127.0.0.1');
CJS
const IP = require('@wnynya/ip');
const ip = new IP('127.0.0.1');
Typescript
import IP from '@wnynya/ip';
const ip: IP = new IP('127.0.0.1');
// Convert IPv4 string to demical & check IP is bogon.
import IP from '@wnynya/ip'; // ESM
const ip = new IP('127.0.0.1');
console.log(ip.toDemical()); // true
console.log(ip.isBogon()); // true
console.log(ip.in(new IP('127.0.0.1', '127.0.0.255'))); // true
console.log(ip.in(new IP('127.0.1.0/24'))); // false
value
<string|number|bigint>
IP value.
- Returns:
<string>
Returns full string of IP.
- Returns:
<bigint>
Returns demical value of IP.
- Returns:
<boolean>
Check IP is IPv4.
- Returns:
<boolean>
Check IP is IPv6.
- Returns:
<IP>
Convert IPv4 IP
to IPv6 IP
- Returns:
<boolean>
Check IP has subnet mask (suffix).
- Returns:
<Object>
Returns subnet range.
- Returns:
<IP[]>
Returns array of subnet range IPs.
-
from
<IP>
IP value. -
to
<IP>
IP value. -
Returns:
<boolean>
Check IP is in range.
If from
IP has subnet range, Check IP is in subnet range.
- Returns:
<boolean>
Check IP is bogon.
- Returns:
<string>
If IP is bogon, returns reason of bogon.