generate-ip 2.1.2 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -9
- package/dist/cli.min.js +5 -4
- package/dist/generate-ip.min.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
# > generate-ip
|
|
2
2
|
|
|
3
|
-
### Randomly generate
|
|
3
|
+
### Randomly generate, format, and validate IPv4/IPv6 addresses.
|
|
4
4
|
|
|
5
5
|
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
6
|
-
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-ip-2.1
|
|
6
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-ip-2.2.1"><img height=31 src="https://img.shields.io/badge/Latest_Build-2.2.1-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
7
7
|
<a href="https://www.npmjs.com/package/generate-ip?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/generate-ip?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
8
|
+
<a href="https://github.com/adamlui/js-utils/blob/generate-ip-2.2.1/generate-ip/dist/generate-ip.min.js"><img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/generate-ip/dist/generate-ip.min.js?branch=generate-ip-2.2.1&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
8
9
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:generate-ip/src/generate-ip.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Agenerate-ip%2Fsrc%2Fgenerate-ip.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
10
|
+
<a href="https://github.com/toolleeo/cli-apps#networking"><img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
11
|
+
<a href="https://www.jsdelivr.com/package/npm/generate-ip?tab=stats"><img height=31 src="https://img.shields.io/jsdelivr/npm/hw/generate-ip?style=for-the-badge&logo=jsdelivr&logoColor=white&label=jsDelivr%20Hits&labelColor=464646&color=49c5d8"></a>
|
|
9
12
|
|
|
10
13
|
<br>
|
|
11
14
|
|
|
12
15
|
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
13
16
|
|
|
17
|
+
## 💡 About
|
|
18
|
+
|
|
19
|
+
**generate-ip** is a lightweight, easy-to-use library that allows you to randomly generate, format & validate IP address(es).
|
|
20
|
+
|
|
21
|
+
- **No external dependencies —** Only built-in crypto methods used for secure randomization
|
|
22
|
+
- **Multi-protocol support —** IPv4 + IPv6 addresses supported
|
|
23
|
+
- **Multi-environment support —** Use in Node.js or the web browser
|
|
24
|
+
- **Command line usable —** Just type `generate-ip`, that's it
|
|
25
|
+
|
|
26
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
27
|
+
|
|
14
28
|
## ⚡ Installation
|
|
15
29
|
|
|
16
30
|
As a **global utility**:
|
|
@@ -58,14 +72,14 @@ const { ipv4, ipv6 } = require('generate-ip');
|
|
|
58
72
|
#### <> HTML script tag:
|
|
59
73
|
|
|
60
74
|
```html
|
|
61
|
-
<script src="https://cdn.jsdelivr.net/npm/generate-ip@2.1
|
|
75
|
+
<script src="https://cdn.jsdelivr.net/npm/generate-ip@2.2.1/dist/generate-ip.min.js"></script>
|
|
62
76
|
```
|
|
63
77
|
|
|
64
78
|
#### ES6:
|
|
65
79
|
|
|
66
80
|
```js
|
|
67
81
|
(async () => {
|
|
68
|
-
await import('https://cdn.jsdelivr.net/npm/generate-ip@2.1
|
|
82
|
+
await import('https://cdn.jsdelivr.net/npm/generate-ip@2.2.1/dist/generate-ip.min.js');
|
|
69
83
|
// Your code here...
|
|
70
84
|
})();
|
|
71
85
|
```
|
|
@@ -74,7 +88,7 @@ const { ipv4, ipv6 } = require('generate-ip');
|
|
|
74
88
|
|
|
75
89
|
```js
|
|
76
90
|
...
|
|
77
|
-
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.1
|
|
91
|
+
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.2.1/dist/generate-ip.min.js
|
|
78
92
|
// ==/UserScript==
|
|
79
93
|
|
|
80
94
|
// Your code here...
|
|
@@ -82,7 +96,7 @@ const { ipv4, ipv6 } = require('generate-ip');
|
|
|
82
96
|
|
|
83
97
|
<br>
|
|
84
98
|
|
|
85
|
-
📝 **Note:** To always import the latest version (not recommended in production!) remove the `@2.1
|
|
99
|
+
📝 **Note:** To always import the latest version (not recommended in production!) remove the `@2.2.1` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js`
|
|
86
100
|
|
|
87
101
|
<br>
|
|
88
102
|
|
|
@@ -265,7 +279,11 @@ When installed [globally](#-installation), **generate-ip** can also be used from
|
|
|
265
279
|
$ generate-ip
|
|
266
280
|
```
|
|
267
281
|
|
|
268
|
-
|
|
282
|
+
Sample output:
|
|
283
|
+
|
|
284
|
+
<img src="https://github.com/adamlui/js-utils/blob/main/generate-ip/media/images/sample-cli-output.jpg">
|
|
285
|
+
|
|
286
|
+
📝 **Note:** To generate multiple IP addresses, pass `--qty=n` where `n` is the number of IPs to generate.
|
|
269
287
|
|
|
270
288
|
#
|
|
271
289
|
|
|
@@ -273,6 +291,9 @@ Generated IP is logged to the console + copied to the clipboard.
|
|
|
273
291
|
|
|
274
292
|
```
|
|
275
293
|
Parameter options:
|
|
294
|
+
--qty=n Generate n IP address(es).
|
|
295
|
+
|
|
296
|
+
Boolean options:
|
|
276
297
|
-q, --quiet Suppress all logging except errors.
|
|
277
298
|
|
|
278
299
|
Info commands:
|
|
@@ -298,6 +319,30 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
298
319
|
|
|
299
320
|
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
300
321
|
|
|
301
|
-
|
|
302
|
-
|
|
322
|
+
## 🛠️ Related utilities
|
|
323
|
+
|
|
324
|
+
### [🔒 generate-pw](../generate-pw)
|
|
325
|
+
|
|
326
|
+
> Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
327
|
+
<br>[Install](https://github.com/adamlui/js-utils/tree/main/generate-pw#-installation) /
|
|
328
|
+
[Readme](https://github.com/adamlui/js-utils/tree/main/generate-pw#readme) /
|
|
329
|
+
[API usage](https://github.com/adamlui/js-utils/tree/main/generate-pw#-api-usage) /
|
|
330
|
+
[CLI usage](https://github.com/adamlui/js-utils/tree/main/generate-pw#-command-line-usage) /
|
|
331
|
+
[Discuss](https://js-utils.com/discussions)
|
|
332
|
+
|
|
333
|
+
### <a href="https://js-utils.com/geolocate"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/geolocate/media/images/icons/wire-globe/white/icon32.png"><img height=22 src="https://raw.githubusercontent.com/adamlui/js-utils/main/geolocate/media/images/icons/wire-globe/black/icon32.png"></picture> geolocate</a>
|
|
334
|
+
|
|
335
|
+
> Fetch IP geolocation data from the CLI.
|
|
336
|
+
<br>[Install](https://github.com/adamlui/js-utils/tree/main/geolocate#-installation) /
|
|
337
|
+
[Readme](https://github.com/adamlui/js-utils/tree/main/geolocate#readme) /
|
|
338
|
+
[CLI usage](https://github.com/adamlui/js-utils/tree/main/geolocate#-command-line-usage) /
|
|
339
|
+
[API usage](https://github.com/adamlui/js-utils/tree/main/geolocate#-api-usage) /
|
|
340
|
+
[Discuss](https://js-utils.com/discussions)
|
|
341
|
+
|
|
342
|
+
<br>
|
|
343
|
+
|
|
344
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
345
|
+
|
|
346
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/white/icon32x27.png"><img height=11 src="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.com">**More JavaScript utilities**</a> /
|
|
347
|
+
<a href="https://js-utils.com/discussions">Discuss</a> /
|
|
303
348
|
<a href="#-generate-ip">Back to top ↑</a>
|
package/dist/cli.min.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const e=require(__dirname.match(/src/)?"./generate-ip":"./generate-ip.min")["ipv4"],o=require("child_process")["execSync"],
|
|
3
|
-
${
|
|
4
|
-
${
|
|
5
|
-
${t}
|
|
2
|
+
const e=require(__dirname.match(/src/)?"./generate-ip":"./generate-ip.min")["ipv4"],o=require("child_process")["execSync"],n="[0m",t="[1;91m",i="[1;33m",a={},p={paramOptions:{qty:/^--?qu?a?n?ti?t?y=.*$/},flags:{quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(o=>{var e,s,r;o.startsWith("-")&&(e=Object.keys(p.paramOptions).find(e=>p.paramOptions[e].test(o)),r=Object.keys(p.flags).find(e=>p.flags[e].test(o)),s=Object.keys(p.infoCmds).find(e=>p.infoCmds[e].test(o)),r?a[r]=!0:e?(r=o.split("=")[1],a[e]=parseInt(r)||r):s||(console.error(`
|
|
3
|
+
${t}ERROR: Arg [${o}] not recognized.`+n),console.info(`
|
|
4
|
+
${i}Valid arguments are below.`+n),c(["paramOptions","flags","infoCmds"]),process.exit(1)))}),process.argv.some(e=>p.infoCmds.help.test(e)))c();else if(process.argv.some(e=>p.infoCmds.version.test(e)))console.info("v"+require("./package.json").version);else{a.qty&&(isNaN(a.qty)||a.qty<1)&&(console.error(`
|
|
5
|
+
${t}Error: [qty] argument can only be > 0.`+n),process.exit(1));const r=e.generate({qty:a.qty||1,verbose:!a.quietMode});a.quietMode||(1<a.qty&&console.info(`[ ${r.join(", ")} ]`),console.info("\nCopying to clipboard...")),s(Array.isArray(r)?r.join("\n"):r)}function c(e=["cmdFormat","paramOptions","flags","infoCmds"]){const o={cmdFormat:[`
|
|
6
|
+
${i}generate-ip [options|commands]`+n],paramOptions:["\nParameter options:"," --qty=n Generate n IP address(es)."],flags:["\nBoolean options:"," -q, --quiet Suppress all logging except errors."],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{o[e]?.forEach(e=>{{const r=process.stdout.columns||80,n=[],o=e.match(/\S+|\s+/g);let s="";o.forEach(e=>{var o=r-(0===n.length?0:29);s.length+e.length>o&&(n.push(0===n.length?s:s.trimStart()),s=""),s+=e}),n.push(0===n.length?s:s.trimStart()),n.forEach((e,o)=>console.info(0===o?e:" ".repeat(29)+e))}})})}function s(e){e=e.replace(/\s+$/,"").replace(/"/g,'""'),"darwin"===process.platform?o(`printf "${e}" | pbcopy`):"linux"===process.platform?o(`printf "${e}" | xclip -selection clipboard`):"win32"===process.platform&&o(`Set-Clipboard -Value "${e}"`,{shell:"powershell"})}
|
package/dist/generate-ip.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let
|
|
1
|
+
let s;try{({randomInt:s}=require("crypto"))}catch(e){const t=window.crypto||window.msCrypto;s=(e,o)=>{var r=t?.getRandomValues(new Uint32Array(1))[0]/4294967295||Math.random();return Math.floor(r*(o-e))+e}}const i={generate:function(o={}){var e={verbose:!0,qty:1};if(f(o,e,"ipv4.generate({ verbose: false, qty: 3 })")){(o={...e,...o}).verbose&&console.info(`ipv4.generate() » Generating IPv4 address${1<o.qty?"es":""}...`);var r=[];if(1<o.qty)for(let e=0;e<o.qty;e++)r.push(this.generate({...o,qty:1,verbose:!1}));else{var t=[];for(let e=0;e<4;e++)t.push(s(0,256));r.push(t.join("."))}e=1<o.qty?r:r[0];return o.verbose&&(console.info(`ipv4.generate() » IPv4 address${1<o.qty?"es":""} generated!`),1===o.qty?console.info("ipv4.generate() » "+e):"undefined"!=typeof require&&require.main.filename.endsWith("cli.js")||console.info("ipv4.generate() » Check returned array.")),e}},validate:function(e,o={}){var r={verbose:!0};return"string"!=typeof e?console.error("ipv4.validate() » ERROR: 1st arg <address> must be a string."):f(o,r,"ipv4.validate('0.0.255.255', { verbose: false })")?((o={...r,...o}).verbose&&console.info("ipv4.validate() » Validating IPv4 address..."),e=!(4!==(r=e.split(".")).length||r.some(e=>!/^\d+$/.test(e)||parseInt(e,10)<0||255<parseInt(e,10))),o.verbose&&console.info(`ipv4.validate() » IP is ${e?"":"in"}valid IPv4 address!`),e):void 0}},e={generate:function(o={}){var e={verbose:!0,qty:1,leadingZeros:!1,doubleColon:!0};if(f(o,e,"ipv6.generate({ leadingZeros: true, qty: 5 })")){(o={...e,...o}).verbose&&console.info(`ipv6.generate() » Generating IPv6 address${1<o.qty?"es":""}...`);var r=[];if(1<o.qty)for(let e=0;e<o.qty;e++)r.push(this.generate({...o,qty:1,verbose:!1}));else{const t=[],{qty:n,...i}=o;for(let e=0;e<8;e++){let o="";for(let e=0;e<4;e++)o+=s(0,16).toString(16);t.push(o)}r.push(this.format(t.join(":"),{...i,verbose:!1}))}e=1<o.qty?r:r[0];return o.verbose&&(console.info(`ipv6.generate() » IPv6 address${1<o.qty?"es":""} generated!`),console.info(1===o.qty?"ipv6.generate() » "+e:"ipv6.generate() » Check returned array.")),e}},format:function(o,r={}){var t,n={verbose:!0,leadingZeros:!1,doubleColon:!0};if("string"!=typeof o)return console.error("ipv6.format() » ERROR: 1st arg <address> must be a string.");if(!this.validate(o,{verbose:!1}))return console.error(`ipv6.format() » ERROR: ${o} is not a valid IPv6 address.`);if(f(r,n,"ipv6.format('0d::ffff:192.1.56.10/96', { leadingZeros: true, doubleColon: false })")){r={...n,...r};let e=o;if(e=r.doubleColon?(r.verbose&&console.info("ipv6.format() » Replacing zero series w/ '::'..."),e.replace(/:(?:0+:)+/,"::")):(r.verbose&&console.info("ipv6.format() » Expanding '::' into zero series..."),n=e.split(":").filter(Boolean).length,t=r.leadingZeros?"0000":"0",n=Array(8-n).fill(t).join(":"),e.replace("::",`:${n}:`)),r.leadingZeros){r.verbose&&console.info("ipv6.format() » Adding leading zeros...");var i=e.split(":");for(let e=0;e<i.length;e++)for(;i[e].length<4;)i[e]="0"+i[e];e=i.join(":")}else r.verbose&&console.info("ipv6.format() » Stripping leading zeros..."),e=o.replace(/(^|(?<=:))0+(?!:)/g,"$1");return r.verbose&&(e!==o?console.info("ipv6.format() » IP formatted successfully!"):console.info("ipv6.format() » IP already formatted to specs."),console.info("ipv6.format() » "+e)),e}},validate:function(e,o={}){var r={verbose:!0};if("string"!=typeof e)return console.error("ipv6.validate() » ERROR: 1st arg <address> must be a string.");if(f(o,r,"ipv6.validate('0:0:0:0:0:ffff:192.1.56.10/96', { verbose: false })")){(o={...r,...o}).verbose&&console.info("ipv6.validate() » Validating IPv6 address...");const t=e.split(/::?/),n=t[t.length-1];r=!(e.includes("::")&&2<e.split("::").length||/:{3,}/g.test(e)||t.length<2||8<t.length||t.some(e=>!(/^[\dA-Fa-f]{1,4}$/.test(e)||e===n&&i.validate(n.replace(/\/(?:0|(?:[1-2]?\d)|32|96)$/,""),{verbose:!1}))));return o.verbose&&console.info(`ipv6.validate() » IP is ${r?"":"in"}valid IPv6 address!`),r}}};function f(e,o,r){const t=(f.caller?.name||"validateOptions")+"() » ",n=JSON.stringify(o,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),i=Object.keys(o).join(", "),s=Object.keys(o).filter(e=>"boolean"==typeof o[e]),a=Object.keys(o).filter(e=>Number.isInteger(o[e]));var l=()=>{console.info(t+`Valid options: [ ${i} ]`),console.info(t+"If omitted, default settings are: "+n)};if("object"!=typeof e)return console.error(t+"ERROR: [options] can only be an object of key/values."),console.info(t+"Example valid call: "+r),l(),!1;for(const v in e){if(!Object.prototype.hasOwnProperty.call(o,v))return console.error(t+`ERROR: \`${v}\` is an invalid option.`),l(),!1;if(s.includes(v)&&"boolean"!=typeof e[v])return console.error(t+`ERROR: [${v}] option can only be \`true\` or \`false\`.`),!1;if(a.includes(v)&&(e[v]=parseInt(e[v],10),isNaN(e[v])||e[v]<1))return console.error(t+`ERROR: [${v}] option can only be an integer > 0.`),!1}return!0}try{module.exports={ipv4:i,ipv6:e}}catch(e){}try{window.ipv4=i,window.ipv6=e}catch(e){}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generate-ip",
|
|
3
|
-
"version": "2.1
|
|
4
|
-
"description": "Randomly generate
|
|
3
|
+
"version": "2.2.1",
|
|
4
|
+
"description": "Randomly generate, format, and validate IPv4/IPv6 addresses.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
7
7
|
"email": "adam@kudoai.com",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"mac"
|
|
50
50
|
],
|
|
51
51
|
"bugs": {
|
|
52
|
-
"url": "https://
|
|
52
|
+
"url": "https://js-utils.com/issues"
|
|
53
53
|
},
|
|
54
54
|
"funding": {
|
|
55
55
|
"type": "github",
|
|
56
56
|
"url": "https://github.com/sponsors/adamlui"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@adamlui/minify.js": "^1.4.
|
|
59
|
+
"@adamlui/minify.js": "^1.4.10"
|
|
60
60
|
}
|
|
61
61
|
}
|