Added reserved IP utility
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.26.8",
|
"version": "0.26.9",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
11
src/misc.ts
11
src/misc.ts
@ -47,6 +47,17 @@ export function ipV6ToV4(ip: string) {
|
|||||||
return ipv4;
|
return ipv4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if IP is reserved, e.g. localhost, private IPs, etc.
|
||||||
|
* @param {string} ip
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
export function reservedIp(ip: string): boolean {
|
||||||
|
if(ip == 'localhost') return true;
|
||||||
|
return /\b(10\.(?:[0-9]{1,3}\.){2}[0-9]{1,3})\b|\b(172\.(?:1[6-9]|2[0-9]|3[0-1])\.(?:[0-9]{1,3}\.)[0-9]{1,3})\b|\b(192\.168\.(?:[0-9]{1,3}\.)[0-9]{1,3})\b/.test(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a function that listens for events and handles them accordingly.
|
* Represents a function that listens for events and handles them accordingly.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user