generate-ip 2.2.11 โ 2.3.0
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 +96 -34
- package/dist/cli.min.js +8 -8
- package/dist/generate-ip.min.js +3 -3
- package/docs/README.md +96 -34
- package/docs/SECURITY.md +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
1
|
+
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils/generate-ip/media/images/icons/node-graph/white/icon55x49.png"><img height=32 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils/generate-ip/media/images/icons/node-graph/black/icon55x49.png"></picture> generate-ip
|
|
2
2
|
|
|
3
|
-
### Randomly generate, format, and validate IPv4
|
|
3
|
+
### Randomly generate, format, and validate IPv4 + IPv6 + MAC 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.
|
|
6
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-ip-2.3.0"><img height=31 src="https://img.shields.io/badge/Latest_Build-2.3.0-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.
|
|
8
|
+
<a href="https://github.com/adamlui/js-utils/blob/generate-ip-2.3.0/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.3.0&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
9
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
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
11
|
<a href="https://www.jsdelivr.com/package/npm/generate-ip?tab=stats"><img height=31 src="https://img.shields.io/jsdelivr/npm/hm/generate-ip?style=for-the-badge&logo=jsdelivr&logoColor=white&label=jsDelivr%20Hits&labelColor=464646&color=49c5d8"></a>
|
|
12
12
|
|
|
13
13
|
<br>
|
|
14
14
|
|
|
15
|
-
<img height=6px width="100%" src="https://
|
|
15
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
16
16
|
|
|
17
17
|
## ๐ก About
|
|
18
18
|
|
|
19
19
|
**generate-ip** is a lightweight, easy-to-use library that allows you to randomly generate, format & validate IP address(es).
|
|
20
20
|
|
|
21
21
|
- **No external dependencies โ** Only built-in crypto methods used for secure randomization
|
|
22
|
-
- **Multi-protocol support โ** IPv4 + IPv6 addresses supported
|
|
22
|
+
- **Multi-protocol support โ** IPv4 + IPv6 + MAC addresses supported
|
|
23
23
|
- **Multi-environment support โ** Use in Node.js or the web browser
|
|
24
24
|
- **Command line usable โ** Just type `generate-ip`, that's it
|
|
25
25
|
|
|
26
|
-
<img height=6px width="100%" src="https://
|
|
26
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
27
27
|
|
|
28
28
|
## โก Installation
|
|
29
29
|
|
|
@@ -47,48 +47,48 @@ $ npm install generate-ip
|
|
|
47
47
|
|
|
48
48
|
<br>
|
|
49
49
|
|
|
50
|
-
<img height=6px width="100%" src="https://
|
|
50
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
51
51
|
|
|
52
52
|
## ๐ Importing the APIs
|
|
53
53
|
|
|
54
|
-
### <img height=18 src="https://
|
|
54
|
+
### <img height=18 src="https://media.js-utils.com/images/icons/platforms/node.js/icon25x28.png"> Node.js
|
|
55
55
|
|
|
56
56
|
#### ECMAScript*:
|
|
57
57
|
|
|
58
58
|
```js
|
|
59
|
-
import { ipv4, ipv6 } from 'generate-ip';
|
|
59
|
+
import { ipv4, ipv6, mac } from 'generate-ip';
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
#### CommonJS:
|
|
63
63
|
|
|
64
64
|
```js
|
|
65
|
-
const { ipv4, ipv6 } = require('generate-ip');
|
|
65
|
+
const { ipv4, ipv6, mac } = require('generate-ip');
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
###### _*Node.js version 14 or higher required_
|
|
69
69
|
|
|
70
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
70
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://media.js-utils.com/images/icons/platforms/web/light/icon25.png"><img width=16 src="https://media.js-utils.com/images/icons/platforms/web/dark/icon25.png"></picture> Web
|
|
71
71
|
|
|
72
72
|
#### <> HTML script tag:
|
|
73
73
|
|
|
74
74
|
```html
|
|
75
|
-
<script src="https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
75
|
+
<script src="https://cdn.jsdelivr.net/npm/generate-ip@2.3.0/dist/generate-ip.min.js"></script>
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
#### ES6:
|
|
79
79
|
|
|
80
80
|
```js
|
|
81
81
|
(async () => {
|
|
82
|
-
await import('https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
82
|
+
await import('https://cdn.jsdelivr.net/npm/generate-ip@2.3.0/dist/generate-ip.min.js');
|
|
83
83
|
// Your code here...
|
|
84
84
|
})();
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
### <img height=17 src="https://
|
|
87
|
+
### <img height=17 src="https://cdn.jsdelivr.net/gh/KudoAI/chatgpt.js/starters/media/images/icons/tampermonkey-icon28.png"><img height=17.5 src="https://cdn.jsdelivr.net/gh/KudoAI/chatgpt.js/starters/media/images/icons/violentmonkey-icon100.png"> Greasemonkey
|
|
88
88
|
|
|
89
89
|
```js
|
|
90
90
|
...
|
|
91
|
-
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
91
|
+
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.3.0/dist/generate-ip.min.js
|
|
92
92
|
// ==/UserScript==
|
|
93
93
|
|
|
94
94
|
// Your code here...
|
|
@@ -96,11 +96,11 @@ const { ipv4, ipv6 } = require('generate-ip');
|
|
|
96
96
|
|
|
97
97
|
<br>
|
|
98
98
|
|
|
99
|
-
๐ **Note:** To always import the latest version (not recommended in production!) remove the `@2.
|
|
99
|
+
๐ **Note:** To always import the latest version (not recommended in production!) remove the `@2.3.0` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js`
|
|
100
100
|
|
|
101
101
|
<br>
|
|
102
102
|
|
|
103
|
-
<img height=6px width="100%" src="https://
|
|
103
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
104
104
|
|
|
105
105
|
## ๐ API usage
|
|
106
106
|
|
|
@@ -214,7 +214,6 @@ Name | Type | Description | Default Value
|
|
|
214
214
|
|
|
215
215
|
#
|
|
216
216
|
|
|
217
|
-
|
|
218
217
|
#### `ipv6.format(ipv6address[, options])`
|
|
219
218
|
|
|
220
219
|
Formats an IPv6 address according to `options` passed, returning a string:
|
|
@@ -267,9 +266,72 @@ Name | Type | Description | Default Value
|
|
|
267
266
|
------------|---------|-----------------------------------|---------------
|
|
268
267
|
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
269
268
|
|
|
269
|
+
#
|
|
270
|
+
|
|
271
|
+
### `mac` methods
|
|
272
|
+
|
|
273
|
+
๐ก Use the `mac` methods to [**generate**](#macgenerateoptions) and [**validate**](#macvalidateaddress-options) MAC addresses.
|
|
274
|
+
|
|
275
|
+
#
|
|
276
|
+
|
|
277
|
+
#### `mac.generate([options])`
|
|
278
|
+
|
|
279
|
+
Generates **one** MAC address if `qty` option is not given, returning a string:
|
|
280
|
+
|
|
281
|
+
```js
|
|
282
|
+
const macAddress = mac.generate();
|
|
283
|
+
console.log(macAddress); // sample output: '1d:3a:af:21:b1:8c'
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
...or **multiple** MAC addresses if `qty` option is given, returning an array of strings:
|
|
287
|
+
|
|
288
|
+
```js
|
|
289
|
+
const macAddresses = mac.generate({ qty: 2 });
|
|
290
|
+
console.log(macAddresses);
|
|
291
|
+
|
|
292
|
+
/* sample output:
|
|
293
|
+
|
|
294
|
+
mac.generate() ยป Generating MAC addresses...
|
|
295
|
+
mac.generate() ยป MAC addresses generated!
|
|
296
|
+
mac.generate() ยป 1d:3a:af:21:b1:8c, af:fb:6f:b6:1b:8a
|
|
297
|
+
[ '1d:3a:af:21:b1:8c', 'af:fb:6f:b6:1b:8a' ]
|
|
298
|
+
*/
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Available options:
|
|
302
|
+
|
|
303
|
+
Name | Type | Description | Default Value
|
|
304
|
+
---------------|---------|--------------------------------------|---------------
|
|
305
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
306
|
+
`qty` | Integer | Number of IP addresses to generate. | `1`
|
|
307
|
+
|
|
308
|
+
#
|
|
309
|
+
|
|
310
|
+
#### `mac.validate(address[, options])`
|
|
311
|
+
|
|
312
|
+
Checks if given `address` is a valid MAC address:
|
|
313
|
+
|
|
314
|
+
```js
|
|
315
|
+
const addressIsValid = mac.validate('1d:3a:af:21:b1:8c');
|
|
316
|
+
console.log(addressIsValid);
|
|
317
|
+
|
|
318
|
+
/* outputs:
|
|
319
|
+
|
|
320
|
+
mac.validate() ยป Validating 1d:3a:af:21:b1:8c...
|
|
321
|
+
mac.validate() ยป Address is valid MAC address!
|
|
322
|
+
true
|
|
323
|
+
*/
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Available options (passed as object properties):
|
|
327
|
+
|
|
328
|
+
Name | Type | Description | Default Value
|
|
329
|
+
------------|---------|-----------------------------------|---------------
|
|
330
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
331
|
+
|
|
270
332
|
<br>
|
|
271
333
|
|
|
272
|
-
<img height=6px width="100%" src="https://
|
|
334
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
273
335
|
|
|
274
336
|
## ๐ป Command line usage
|
|
275
337
|
|
|
@@ -281,7 +343,7 @@ $ generate-ip
|
|
|
281
343
|
|
|
282
344
|
Sample output:
|
|
283
345
|
|
|
284
|
-
<img src="https://
|
|
346
|
+
<img src="https://media.generate-ip.org/images/screenshots/cli/generate-ip-cmd-output.jpg">
|
|
285
347
|
|
|
286
348
|
๐ **Note:** To generate multiple IP addresses, pass `--qty=n` where `n` is the number of IPs to generate.
|
|
287
349
|
|
|
@@ -303,7 +365,7 @@ Info commands:
|
|
|
303
365
|
|
|
304
366
|
<br>
|
|
305
367
|
|
|
306
|
-
<img height=6px width="100%" src="https://
|
|
368
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
307
369
|
|
|
308
370
|
## ๐๏ธ MIT License
|
|
309
371
|
|
|
@@ -317,32 +379,32 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
317
379
|
|
|
318
380
|
<br>
|
|
319
381
|
|
|
320
|
-
<img height=6px width="100%" src="https://
|
|
382
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
321
383
|
|
|
322
384
|
## ๐ ๏ธ Related utilities
|
|
323
385
|
|
|
324
386
|
### [๐ generate-pw](../generate-pw) <a href="https://github.com/toolleeo/cli-apps#password-managers"><img height=18 src="https://awesome.re/mentioned-badge.svg"></a>
|
|
325
387
|
|
|
326
388
|
> Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
327
|
-
<br>[Install](https://docs.
|
|
328
|
-
[Readme](https://docs.
|
|
329
|
-
[API usage](https://docs.
|
|
330
|
-
[CLI usage](https://docs.
|
|
389
|
+
<br>[Install](https://docs.generatepw.org/#-installation) /
|
|
390
|
+
[Readme](https://docs.generatepw.org/#readme) /
|
|
391
|
+
[API usage](https://docs.generatepw.org/#-api-usage) /
|
|
392
|
+
[CLI usage](https://docs.generatepw.org/#-command-line-usage) /
|
|
331
393
|
[Discuss](https://github.js-utils.com/discussions)
|
|
332
394
|
|
|
333
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
395
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils/geolocate/media/images/icons/wire-globe/white/icon32.png"><img height=22 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils/geolocate/media/images/icons/wire-globe/black/icon32.png"></picture> [geolocate](https://js-utils.com/geolocate)
|
|
334
396
|
|
|
335
397
|
> Fetch IP geolocation data from the CLI.
|
|
336
|
-
<br>[Install](https://docs.
|
|
337
|
-
[Readme](https://docs.
|
|
338
|
-
[CLI usage](https://docs.
|
|
339
|
-
[API usage](https://docs.
|
|
398
|
+
<br>[Install](https://docs.geolocatejs.org/#-installation) /
|
|
399
|
+
[Readme](https://docs.geolocatejs.org/#readme) /
|
|
400
|
+
[CLI usage](https://docs.geolocatejs.org/#-command-line-usage) /
|
|
401
|
+
[API usage](https://docs.geolocatejs.org/#-api-usage) /
|
|
340
402
|
[Discuss](https://github.js-utils.com/discussions)
|
|
341
403
|
|
|
342
404
|
<br>
|
|
343
405
|
|
|
344
|
-
<img height=6px width="100%" src="https://
|
|
406
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
345
407
|
|
|
346
|
-
<picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
408
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://media.js-utils.com/images/icons/home/white/icon32x27.png"><img height=13 src="https://media.js-utils.com/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.com">**More JavaScript utilities**</a> /
|
|
347
409
|
<a href="https://github.js-utils.com/discussions">Discuss</a> /
|
|
348
410
|
<a href="#-generate-ip">Back to top โ</a>
|
package/dist/cli.min.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* ยฉ 2024 Adam Lui & contributors under the MIT license.
|
|
4
|
-
* Source: https://code.
|
|
5
|
-
* Documentation: https://docs.
|
|
4
|
+
* Source: https://code.generate-ip.org
|
|
5
|
+
* Documentation: https://docs.generate-ip.org
|
|
6
6
|
*/
|
|
7
|
-
const pkgName="generate-ip",copyright="ยฉ 2024 Adam Lui & contributors under the MIT license.",cmdFormat="generate-ip [options|commands]",srcURL="https://code.
|
|
8
|
-
${i+(p.prefix_error||"ERROR")}: `+`Arg [--${o.replace(/-/g,"")}] `+`${p.error_noEqual||"requires '=' followed by a value"}.${t}`),u(),process.exit(1)),
|
|
7
|
+
const pkgName="generate-ip",copyright="ยฉ 2024 Adam Lui & contributors under the MIT license.",cmdFormat="generate-ip [options|commands]",srcURL="https://code.generate-ip.org",docURL="https://docs.generate-ip.org/#-command-line-usage";(async()=>{const e=require(__dirname.match(/src/)?"./generate-ip":"./generate-ip.min")["ipv4"],r=require("fs"),n=require("path"),s=require("child_process")["execSync"],t="[0m",i="[1;91m",a="[1;97m";let l="en";if("win32"==process.platform)try{l=s("(Get-Culture).TwoLetterISOLanguageName",{shell:"powershell",encoding:"utf-8"}).trim()}catch(e){}else{var c=process.env;l=(c.LANG||c.LANGUAGE||c.LC_ALL||c.LC_MESSAGES||c.LC_NAME||"en").split(".")[0]}let p={};var o,c=new Promise((t,i)=>{const a="https://cdn.jsdelivr.net/gh/adamlui/js-utils/generate-ip/_locales/",e=(l?l.replace("-","_"):"en")+"/";let c=a+e+"messages.json",p=0;d(c).then(async function o(e){try{const r=await e.json(),n={};for(const s in r)"object"==typeof r[s]&&"message"in r[s]&&(n[s]=r[s].message);t(n)}catch(e){if(3==++p)return t({});d(c=l.includes("-")&&1==p?c.replace(/([^_]*)_[^/]*(\/.*)/,"$1$2"):a+"en/messages.json").then(o).catch(i)}}).catch(i)});try{p=await c}catch(e){}const m={},f={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,r,n;o.startsWith("-")&&(e=Object.keys(f.paramOptions).find(e=>f.paramOptions[e].test(o)),n=Object.keys(f.flags).find(e=>f.flags[e].test(o)),r=Object.keys(f.infoCmds).find(e=>f.infoCmds[e].test(o)),n?m[n]=!0:e?(o.includes("=")||(console.error(`
|
|
8
|
+
${i+(p.prefix_error||"ERROR")}: `+`Arg [--${o.replace(/-/g,"")}] `+`${p.error_noEqual||"requires '=' followed by a value"}.${t}`),u(),process.exit(1)),n=o.split("=")[1],m[e]=parseInt(n)||n):r||(console.error(`
|
|
9
9
|
${i+(p.prefix_error||"ERROR")}: `+`Arg [${o}] ${p.error_notRecognized||"not recognized"}.[0m`),console.info(`
|
|
10
|
-
${"[1;33m"+(p.info_validArgs||"Valid arguments are below")}.[0m`),h(["paramOptions","flags","infoCmds"]),process.exit(1)))}),process.argv.some(e=>
|
|
10
|
+
${"[1;33m"+(p.info_validArgs||"Valid arguments are below")}.[0m`),h(["paramOptions","flags","infoCmds"]),process.exit(1)))}),process.argv.some(e=>f.infoCmds.help.test(e)))h();else if(process.argv.some(e=>f.infoCmds.version.test(e))){c=s(`npm view ${pkgName} version`).toString().trim()||"none";let e,o=process.cwd();for(;"/"!=o;){var g=n.join(o,"package.json");if(r.existsSync(g)){g=require(g);e=(g.dependencies?.[pkgName]||g.devDependencies?.[pkgName])?.match(/(\d+\.\d+\.\d+)/)[0]||"none";break}o=n.dirname(o)}console.info(`
|
|
11
11
|
${p.prefix_globalVer||"Global version"}: `+c),console.info(`${p.prefix_localVer||"Local version"}: `+e)}else{m.qty&&(isNaN(m.qty)||m.qty<1)&&(console.error(`
|
|
12
12
|
${i+(p.prefix_error||"ERROR")}: [qty] `+`${p.error_nonPositiveNum||"argument can only be > 0"}.${t}`),u(),process.exit(1));c=e.generate({qty:m.qty||1,verbose:!m.quietMode});o=`
|
|
13
|
-
${p.info_copying||"Copying to clipboard"}...`,m.quietMode||console.info(o),o=
|
|
13
|
+
${p.info_copying||"Copying to clipboard"}...`,m.quietMode||console.info(o),o=Array.isArray(c)?c.join("\n"):c,"darwin"==process.platform?s(`printf "${o}" | pbcopy`):"linux"==process.platform?s(`printf "${o}" | xclip -selection clipboard`):"win32"==process.platform&&s(`Set-Clipboard -Value "${o}"`,{shell:"powershell"})}function d(n){return new Promise((r,e)=>{var o=n.match(/^([^:]+):\/\//)[1];/^https?$/.test(o)||e(new Error(`${p.error_invalidURL||"Invalid URL"}.`)),require(o).get(n,e=>{let o="";e.on("data",e=>o+=e),e.on("end",()=>r({json:()=>JSON.parse(o)}))}).on("error",e)})}function h(e=["header","usage","paramOptions","flags","infoCmds"]){var o=`[106m[30m ${pkgName} [0m `;const r={header:["\nโ "+o+(p.appCopyright||copyright),o+(p.prefix_source||"Source")+": "+srcURL],usage:[`
|
|
14
14
|
${a}o ${p.helpSection_usage||"Usage"}:[0m`," [1;97mยป [1;92m"+cmdFormat+t],paramOptions:[`
|
|
15
15
|
${a}o ${p.helpSection_paramOptions||"Parameter options"}:[0m`,` --qty=n ${p.optionDesc_qty||"Generate n IP address(es)"}.`],flags:[`
|
|
16
16
|
${a}o ${p.helpSection_flags||"Boolean options"}:[0m`,` -q, --quiet ${p.optionDesc_quiet||"Suppress all logging except errors"}.`],infoCmds:[`
|
|
17
|
-
${a}o ${p.helpSection_infoCmds||"Info commands"}:[0m`," -h, --help "+(p.optionDesc_help||"Display help screen."),` -v, --version ${p.optionDesc_version||"Show version number"}.`]};e.forEach(i=>{r[i]?.forEach(e=>{{var
|
|
17
|
+
${a}o ${p.helpSection_infoCmds||"Info commands"}:[0m`," -h, --help "+(p.optionDesc_help||"Display help screen."),` -v, --version ${p.optionDesc_version||"Show version number"}.`]};e.forEach(i=>{r[i]?.forEach(e=>{{var n=/header|usage/.test(i)?1:29;const s=process.stdout.columns||80,t=[],o=e.match(/\S+|\s+/g);let r="";o.forEach(e=>{var o=s-(0==t.length?0:n);r.length+"| ".length+e.length>o&&(t.push(0==t.length?r:r.trimStart()),r=""),r+=e}),t.push(0==t.length?r:r.trimStart()),t.forEach((e,o)=>console.info("| "+(0==o?e:" ".repeat(n)+e)))}})}),console.info(`
|
|
18
18
|
${p.info_moreHelp||"For more help"}, ${p.info_visit||"visit"}: `+a+docURL+t)}function u(){console.info(`
|
|
19
|
-
For more help
|
|
19
|
+
${p.info_moreHelp||"For more help"},`+` ${p.info_type||"type"} 'generate-ip --help'`+` ${p.info_or||"or"} ${p.info_visit||"visit"}
|
|
20
20
|
`+a+docURL+t)}})();
|
package/dist/generate-ip.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ยฉ 2024 Adam Lui & contributors under the MIT license.
|
|
3
|
-
* Source: https://code.
|
|
4
|
-
* Documentation: https://docs.
|
|
3
|
+
* Source: https://code.generate-ip.org
|
|
4
|
+
* Documentation: https://docs.generate-ip.org
|
|
5
5
|
*/
|
|
6
|
-
const ipv4={generate:function(o={}){var e={verbose:!0,qty:1};if(validateOptions(o,e,"https://docs.
|
|
6
|
+
const ipv4={generate:function(o={}){var e={verbose:!0,qty:1};if(validateOptions(o,e,"https://docs.generate-ip.org/#ipv4generateoptions","ipv4.generate({ verbose: false, qty: 3 })")){(o={...e,...o}).verbose&&console.info(`ipv4.generate() ยป Generating IPv4 address${1<o.qty?"es":""}...`);var t=[];if(1<o.qty)for(let e=0;e<o.qty;e++)t.push(this.generate({...o,qty:1,verbose:!1}));else{var r=[];for(let e=0;e<4;e++)r.push(randomInt(0,256));t.push(r.join("."))}e=1<o.qty?t:t[0];return o.verbose&&(console.info(`ipv4.generate() ยป IPv4 address${1<o.qty?"es":""} generated!`),console.info("ipv4.generate() ยป "+(1==o.qty?e:e.join(", ")))),e}},validate:function(e,o={}){var t="https://docs.generate-ip.org/#ipv4validateaddress-options",r={verbose:!0};if("string"!=typeof e)console.error("ipv4.validate() ยป ERROR: 1st arg <address> must be a string."),console.info("ipv4.validate() ยป For more help, please visit "+t);else if(validateOptions(o,r,t,"ipv4.validate('0.0.255.255', { verbose: false })"))return(o={...r,...o}).verbose&&console.info(`ipv4.validate() ยป Validating ${e}...`),r=!(4!=(t=e.split(".")).length||t.some(e=>!/^\d+$/.test(e)||parseInt(e,10)<0||255<parseInt(e,10))),o.verbose&&console.info(`ipv4.validate() ยป IP is ${r?"":"in"}valid IPv4 address!`),r}},ipv6={generate:function(o={}){var e={verbose:!0,qty:1,leadingZeros:!1,doubleColon:!0};if(validateOptions(o,e,"https://docs.generate-ip.org/#ipv6generateoptions","ipv6.generate({ leadingZeros: true, qty: 5 })")){(o={...e,...o}).verbose&&console.info(`ipv6.generate() ยป Generating IPv6 address${1<o.qty?"es":""}...`);var t=[];if(1<o.qty)for(let e=0;e<o.qty;e++)t.push(this.generate({...o,qty:1,verbose:!1}));else{const i=[],{qty:n,...s}=o;for(let e=0;e<8;e++){var r=randomHex(4);i.push(r)}t.push(this.format(i.join(":"),{...s,verbose:!1}))}e=1<o.qty?t:t[0];return o.verbose&&(console.info(`ipv6.generate() ยป IPv6 address${1<o.qty?"es":""} generated!`),console.info("ipv6.generate() ยป "+(1==o.qty?e:e.join(", ")))),e}},format:function(o,t={}){var r,e="https://docs.generate-ip.org/#ipv6formatipv6address-options",i={verbose:!0,leadingZeros:!1,doubleColon:!0};if("string"!=typeof o)console.error("ipv6.format() ยป ERROR: 1st arg <ipv6address> must be a string."),console.info("ipv6.format() ยป For more help, please visit "+e);else if(this.validate(o,{verbose:!1})){if(validateOptions(t,i,e,"ipv6.format('0d::ffff:192.1.56.10/96', { leadingZeros: true, doubleColon: false })")){t={...i,...t};let e=o;if(e=t.doubleColon?(t.verbose&&console.info("ipv6.format() ยป Replacing zero series w/ '::'..."),e.replace(/:(?:0+:)+/,"::")):(t.verbose&&console.info("ipv6.format() ยป Expanding '::' into zero series..."),i=e.split(":").filter(Boolean).length,r=t.leadingZeros?"0000":"0",i=Array(8-i).fill(r).join(":"),e.replace("::",`:${i}:`)),t.leadingZeros){t.verbose&&console.info("ipv6.format() ยป Adding leading zeros...");var n=e.split(":");for(let e=0;e<n.length;e++)for(;n[e].length<4;)n[e]="0"+n[e];e=n.join(":")}else t.verbose&&console.info("ipv6.format() ยป Stripping leading zeros..."),e=o.replace(/(^|(?<=:))0+(?!:)/g,"$1");return t.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}}else console.error(`ipv6.format() ยป ERROR: ${o} is not a valid IPv6 address.`),console.info("ipv6.format() ยป For more help, please visit "+e)},validate:function(e,o={}){var t="https://docs.generate-ip.org/#ipv6validateaddress-options",r={verbose:!0};if("string"!=typeof e)console.error("ipv6.validate() ยป ERROR: 1st arg <address> must be a string."),console.info("ipv6.validate() ยป For more help, please visit "+t);else if(validateOptions(o,r,t,"ipv6.validate('0:0:0:0:0:ffff:192.1.56.10/96', { verbose: false })")){(o={...r,...o}).verbose&&console.info(`ipv6.validate() ยป Validating ${e}...`);const i=e.split(/::?/),n=i[i.length-1];t=!(e.includes("::")&&2<e.split("::").length||/:{3,}/g.test(e)||i.length<2||8<i.length||i.some(e=>!(/^[\dA-Fa-f]{1,4}$/.test(e)||e==n&&ipv4.validate(n.replace(/\/(?:0|(?:[1-2]?\d)|32|96)$/,""),{verbose:!1}))));return o.verbose&&console.info(`ipv6.validate() ยป IP is ${t?"":"in"}valid IPv6 address!`),t}}},mac={generate:function(o={}){var e={verbose:!0,qty:1};if(validateOptions(o,e,"https://docs.generate-ip.org/#macgenerateoptions","mac.generate({ verbose: false, qty: 2 })")){(o={...e,...o}).verbose&&console.info(`mac.generate() ยป Generating MAC address${1<o.qty?"es":""}...`);var t=[];if(1<o.qty)for(let e=0;e<o.qty;e++)t.push(this.generate({...o,qty:1,verbose:!1}));else{var[e,r]=Array.from({length:2},()=>{var o=[];for(let e=0;e<3;e++)o.push(randomHex(2));return o.join(":")});t.push(e+":"+r)}e=1<o.qty?t:t[0];return o.verbose&&(console.info(`mac.generate() ยป MAC address${1<o.qty?"es":""} generated!`),console.info("mac.generate() ยป "+(1==o.qty?e:e.join(", ")))),e}},validate:function(e,o={}){var t="https://docs.generate-ip.org/#macvalidateaddress-options",r={verbose:!0};if("string"!=typeof e)console.error("mac.validate() ยป ERROR: 1st arg <address> must be a string."),console.info("mac.validate() ยป For more help, please visit "+t);else if(validateOptions(o,r,t,"mac.validate('00:1A:2B:3C:4D:5E', { verbose: false })"))return(o={...r,...o}).verbose&&console.info(`mac.validate() ยป Validating ${e}...`),t=/^(?:[\dA-Fa-f]{2}[:-]){5}(?:[\dA-Fa-f]{2})$/.test(e),o.verbose&&console.info(`mac.validate() ยป Address is ${t?"":"in"}valid MAC address!`),t}};function randomInt(e,o){var t;return"undefined"==typeof require?(t=(window.crypto||window.msCrypto)?.getRandomValues(new Uint32Array(1))[0]/4294967295||Math.random(),Math.floor(t*(o-e))+e):require("crypto").randomInt(e,o)}function randomHex(o){let t="";for(let e=0;e<o;e++)t+=randomInt(0,16).toString(16);return t}function validateOptions(e,o,t,r){const i=JSON.stringify(o,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),n=Object.keys(o).join(", "),s=Object.keys(o).filter(e=>"boolean"==typeof o[e]),a=Object.keys(o).filter(e=>Number.isInteger(o[e]));let l="validateOptions() ยป ";try{l=validateOptions.caller?.name+"() ยป "}catch(e){}var v=r.split(",").findIndex(e=>e.trim().startsWith("{"))+1,p=(v+=["st","nd","rd"][v-1]||"th",()=>{console.info(`${l}Valid options: [ ${n} ]`),console.info(l+"If omitted, default settings are: "+i)}),d=()=>{console.info(l+"For more help, please visit "+t)};if("object"!=typeof e)return console.error(l+`ERROR: ${"0th"==v?"[O":v+" arg [o"}ptions] can only be an object of key/values.`),console.info(l+"Example valid call: "+r),p(),d(),!1;for(const f in e){if(!Object.prototype.hasOwnProperty.call(o,f))return console.error(`${l}ERROR: \`${f}\` is an invalid option.`),p(),d(),!1;if(s.includes(f)&&"boolean"!=typeof e[f])return console.error(`${l}ERROR: [${f}] option can only be \`true\` or \`false\`.`),d(),!1;if(a.includes(f)&&(e[f]=parseInt(e[f],10),isNaN(e[f])||e[f]<1))return console.error(`${l}ERROR: [${f}] option can only be an integer > 0.`),d(),!1}return!0}const apiAliases={ipv4:["ipV4","IPv4","IPV4","Ipv4","IpV4","ip","IP","Ip"],ipv6:["ipV6","IPv6","IPV6","Ipv6","IpV6"],mac:["MAC","Mac","ethernet","Ethernet"]};try{module.exports={ipv4:ipv4,ipv6:ipv6,mac:mac}}catch(e){}try{window.ipv4=ipv4,window.ipv6=ipv6,window.mac=mac}catch(e){}for(const Ma in apiAliases)apiAliases[Ma].forEach(e=>{try{module.exports[e]=module.exports[Ma]}catch(e){}try{window[e]=window[Ma]}catch(e){}});
|
package/docs/README.md
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
1
|
+
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils/generate-ip/media/images/icons/node-graph/white/icon55x49.png"><img height=32 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils/generate-ip/media/images/icons/node-graph/black/icon55x49.png"></picture> generate-ip
|
|
2
2
|
|
|
3
|
-
### Randomly generate, format, and validate IPv4
|
|
3
|
+
### Randomly generate, format, and validate IPv4 + IPv6 + MAC 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.
|
|
6
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-ip-2.3.0"><img height=31 src="https://img.shields.io/badge/Latest_Build-2.3.0-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.
|
|
8
|
+
<a href="https://github.com/adamlui/js-utils/blob/generate-ip-2.3.0/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.3.0&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
9
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
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
11
|
<a href="https://www.jsdelivr.com/package/npm/generate-ip?tab=stats"><img height=31 src="https://img.shields.io/jsdelivr/npm/hm/generate-ip?style=for-the-badge&logo=jsdelivr&logoColor=white&label=jsDelivr%20Hits&labelColor=464646&color=49c5d8"></a>
|
|
12
12
|
|
|
13
13
|
<br>
|
|
14
14
|
|
|
15
|
-
<img height=6px width="100%" src="https://
|
|
15
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
16
16
|
|
|
17
17
|
## ๐ก About
|
|
18
18
|
|
|
19
19
|
**generate-ip** is a lightweight, easy-to-use library that allows you to randomly generate, format & validate IP address(es).
|
|
20
20
|
|
|
21
21
|
- **No external dependencies โ** Only built-in crypto methods used for secure randomization
|
|
22
|
-
- **Multi-protocol support โ** IPv4 + IPv6 addresses supported
|
|
22
|
+
- **Multi-protocol support โ** IPv4 + IPv6 + MAC addresses supported
|
|
23
23
|
- **Multi-environment support โ** Use in Node.js or the web browser
|
|
24
24
|
- **Command line usable โ** Just type `generate-ip`, that's it
|
|
25
25
|
|
|
26
|
-
<img height=6px width="100%" src="https://
|
|
26
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
27
27
|
|
|
28
28
|
## โก Installation
|
|
29
29
|
|
|
@@ -47,48 +47,48 @@ $ npm install generate-ip
|
|
|
47
47
|
|
|
48
48
|
<br>
|
|
49
49
|
|
|
50
|
-
<img height=6px width="100%" src="https://
|
|
50
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
51
51
|
|
|
52
52
|
## ๐ Importing the APIs
|
|
53
53
|
|
|
54
|
-
### <img height=18 src="https://
|
|
54
|
+
### <img height=18 src="https://media.js-utils.com/images/icons/platforms/node.js/icon25x28.png"> Node.js
|
|
55
55
|
|
|
56
56
|
#### ECMAScript*:
|
|
57
57
|
|
|
58
58
|
```js
|
|
59
|
-
import { ipv4, ipv6 } from 'generate-ip';
|
|
59
|
+
import { ipv4, ipv6, mac } from 'generate-ip';
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
#### CommonJS:
|
|
63
63
|
|
|
64
64
|
```js
|
|
65
|
-
const { ipv4, ipv6 } = require('generate-ip');
|
|
65
|
+
const { ipv4, ipv6, mac } = require('generate-ip');
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
###### _*Node.js version 14 or higher required_
|
|
69
69
|
|
|
70
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
70
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://media.js-utils.com/images/icons/platforms/web/light/icon25.png"><img width=16 src="https://media.js-utils.com/images/icons/platforms/web/dark/icon25.png"></picture> Web
|
|
71
71
|
|
|
72
72
|
#### <> HTML script tag:
|
|
73
73
|
|
|
74
74
|
```html
|
|
75
|
-
<script src="https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
75
|
+
<script src="https://cdn.jsdelivr.net/npm/generate-ip@2.3.0/dist/generate-ip.min.js"></script>
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
#### ES6:
|
|
79
79
|
|
|
80
80
|
```js
|
|
81
81
|
(async () => {
|
|
82
|
-
await import('https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
82
|
+
await import('https://cdn.jsdelivr.net/npm/generate-ip@2.3.0/dist/generate-ip.min.js');
|
|
83
83
|
// Your code here...
|
|
84
84
|
})();
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
### <img height=17 src="https://
|
|
87
|
+
### <img height=17 src="https://cdn.jsdelivr.net/gh/KudoAI/chatgpt.js/starters/media/images/icons/tampermonkey-icon28.png"><img height=17.5 src="https://cdn.jsdelivr.net/gh/KudoAI/chatgpt.js/starters/media/images/icons/violentmonkey-icon100.png"> Greasemonkey
|
|
88
88
|
|
|
89
89
|
```js
|
|
90
90
|
...
|
|
91
|
-
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.
|
|
91
|
+
// @require https://cdn.jsdelivr.net/npm/generate-ip@2.3.0/dist/generate-ip.min.js
|
|
92
92
|
// ==/UserScript==
|
|
93
93
|
|
|
94
94
|
// Your code here...
|
|
@@ -96,11 +96,11 @@ const { ipv4, ipv6 } = require('generate-ip');
|
|
|
96
96
|
|
|
97
97
|
<br>
|
|
98
98
|
|
|
99
|
-
๐ **Note:** To always import the latest version (not recommended in production!) remove the `@2.
|
|
99
|
+
๐ **Note:** To always import the latest version (not recommended in production!) remove the `@2.3.0` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js`
|
|
100
100
|
|
|
101
101
|
<br>
|
|
102
102
|
|
|
103
|
-
<img height=6px width="100%" src="https://
|
|
103
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
104
104
|
|
|
105
105
|
## ๐ API usage
|
|
106
106
|
|
|
@@ -214,7 +214,6 @@ Name | Type | Description | Default Value
|
|
|
214
214
|
|
|
215
215
|
#
|
|
216
216
|
|
|
217
|
-
|
|
218
217
|
#### `ipv6.format(ipv6address[, options])`
|
|
219
218
|
|
|
220
219
|
Formats an IPv6 address according to `options` passed, returning a string:
|
|
@@ -267,9 +266,72 @@ Name | Type | Description | Default Value
|
|
|
267
266
|
------------|---------|-----------------------------------|---------------
|
|
268
267
|
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
269
268
|
|
|
269
|
+
#
|
|
270
|
+
|
|
271
|
+
### `mac` methods
|
|
272
|
+
|
|
273
|
+
๐ก Use the `mac` methods to [**generate**](#macgenerateoptions) and [**validate**](#macvalidateaddress-options) MAC addresses.
|
|
274
|
+
|
|
275
|
+
#
|
|
276
|
+
|
|
277
|
+
#### `mac.generate([options])`
|
|
278
|
+
|
|
279
|
+
Generates **one** MAC address if `qty` option is not given, returning a string:
|
|
280
|
+
|
|
281
|
+
```js
|
|
282
|
+
const macAddress = mac.generate();
|
|
283
|
+
console.log(macAddress); // sample output: '1d:3a:af:21:b1:8c'
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
...or **multiple** MAC addresses if `qty` option is given, returning an array of strings:
|
|
287
|
+
|
|
288
|
+
```js
|
|
289
|
+
const macAddresses = mac.generate({ qty: 2 });
|
|
290
|
+
console.log(macAddresses);
|
|
291
|
+
|
|
292
|
+
/* sample output:
|
|
293
|
+
|
|
294
|
+
mac.generate() ยป Generating MAC addresses...
|
|
295
|
+
mac.generate() ยป MAC addresses generated!
|
|
296
|
+
mac.generate() ยป 1d:3a:af:21:b1:8c, af:fb:6f:b6:1b:8a
|
|
297
|
+
[ '1d:3a:af:21:b1:8c', 'af:fb:6f:b6:1b:8a' ]
|
|
298
|
+
*/
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Available options:
|
|
302
|
+
|
|
303
|
+
Name | Type | Description | Default Value
|
|
304
|
+
---------------|---------|--------------------------------------|---------------
|
|
305
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
306
|
+
`qty` | Integer | Number of IP addresses to generate. | `1`
|
|
307
|
+
|
|
308
|
+
#
|
|
309
|
+
|
|
310
|
+
#### `mac.validate(address[, options])`
|
|
311
|
+
|
|
312
|
+
Checks if given `address` is a valid MAC address:
|
|
313
|
+
|
|
314
|
+
```js
|
|
315
|
+
const addressIsValid = mac.validate('1d:3a:af:21:b1:8c');
|
|
316
|
+
console.log(addressIsValid);
|
|
317
|
+
|
|
318
|
+
/* outputs:
|
|
319
|
+
|
|
320
|
+
mac.validate() ยป Validating 1d:3a:af:21:b1:8c...
|
|
321
|
+
mac.validate() ยป Address is valid MAC address!
|
|
322
|
+
true
|
|
323
|
+
*/
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Available options (passed as object properties):
|
|
327
|
+
|
|
328
|
+
Name | Type | Description | Default Value
|
|
329
|
+
------------|---------|-----------------------------------|---------------
|
|
330
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
331
|
+
|
|
270
332
|
<br>
|
|
271
333
|
|
|
272
|
-
<img height=6px width="100%" src="https://
|
|
334
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
273
335
|
|
|
274
336
|
## ๐ป Command line usage
|
|
275
337
|
|
|
@@ -281,7 +343,7 @@ $ generate-ip
|
|
|
281
343
|
|
|
282
344
|
Sample output:
|
|
283
345
|
|
|
284
|
-
<img src="https://
|
|
346
|
+
<img src="https://media.generate-ip.org/images/screenshots/cli/generate-ip-cmd-output.jpg">
|
|
285
347
|
|
|
286
348
|
๐ **Note:** To generate multiple IP addresses, pass `--qty=n` where `n` is the number of IPs to generate.
|
|
287
349
|
|
|
@@ -303,7 +365,7 @@ Info commands:
|
|
|
303
365
|
|
|
304
366
|
<br>
|
|
305
367
|
|
|
306
|
-
<img height=6px width="100%" src="https://
|
|
368
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
307
369
|
|
|
308
370
|
## ๐๏ธ MIT License
|
|
309
371
|
|
|
@@ -317,32 +379,32 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
317
379
|
|
|
318
380
|
<br>
|
|
319
381
|
|
|
320
|
-
<img height=6px width="100%" src="https://
|
|
382
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
321
383
|
|
|
322
384
|
## ๐ ๏ธ Related utilities
|
|
323
385
|
|
|
324
386
|
### [๐ generate-pw](../generate-pw) <a href="https://github.com/toolleeo/cli-apps#password-managers"><img height=18 src="https://awesome.re/mentioned-badge.svg"></a>
|
|
325
387
|
|
|
326
388
|
> Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
327
|
-
<br>[Install](https://docs.
|
|
328
|
-
[Readme](https://docs.
|
|
329
|
-
[API usage](https://docs.
|
|
330
|
-
[CLI usage](https://docs.
|
|
389
|
+
<br>[Install](https://docs.generatepw.org/#-installation) /
|
|
390
|
+
[Readme](https://docs.generatepw.org/#readme) /
|
|
391
|
+
[API usage](https://docs.generatepw.org/#-api-usage) /
|
|
392
|
+
[CLI usage](https://docs.generatepw.org/#-command-line-usage) /
|
|
331
393
|
[Discuss](https://github.js-utils.com/discussions)
|
|
332
394
|
|
|
333
|
-
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
395
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/adamlui/js-utils/geolocate/media/images/icons/wire-globe/white/icon32.png"><img height=22 src="https://cdn.jsdelivr.net/gh/adamlui/js-utils/geolocate/media/images/icons/wire-globe/black/icon32.png"></picture> [geolocate](https://js-utils.com/geolocate)
|
|
334
396
|
|
|
335
397
|
> Fetch IP geolocation data from the CLI.
|
|
336
|
-
<br>[Install](https://docs.
|
|
337
|
-
[Readme](https://docs.
|
|
338
|
-
[CLI usage](https://docs.
|
|
339
|
-
[API usage](https://docs.
|
|
398
|
+
<br>[Install](https://docs.geolocatejs.org/#-installation) /
|
|
399
|
+
[Readme](https://docs.geolocatejs.org/#readme) /
|
|
400
|
+
[CLI usage](https://docs.geolocatejs.org/#-command-line-usage) /
|
|
401
|
+
[API usage](https://docs.geolocatejs.org/#-api-usage) /
|
|
340
402
|
[Discuss](https://github.js-utils.com/discussions)
|
|
341
403
|
|
|
342
404
|
<br>
|
|
343
405
|
|
|
344
|
-
<img height=6px width="100%" src="https://
|
|
406
|
+
<img height=6px width="100%" src="https://media.js-utils.com/images/separators/gradient-aqua.png">
|
|
345
407
|
|
|
346
|
-
<picture><source media="(prefers-color-scheme: dark)" srcset="https://
|
|
408
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://media.js-utils.com/images/icons/home/white/icon32x27.png"><img height=13 src="https://media.js-utils.com/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.com">**More JavaScript utilities**</a> /
|
|
347
409
|
<a href="https://github.js-utils.com/discussions">Discuss</a> /
|
|
348
410
|
<a href="#-generate-ip">Back to top โ</a>
|
package/docs/SECURITY.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# ๐ก๏ธ Security Policy
|
|
2
2
|
|
|
3
|
-
If you find a vulnerability, please open a [draft security advisory](https://github.
|
|
3
|
+
If you find a vulnerability, please open a [draft security advisory](https://github.js-utils.com/security/advisories/new).
|
|
4
4
|
|
|
5
5
|
Pull requests are also welcome, but for safety reasons, send an email to <adam@kudoai.com> and wait for a response before making it public.
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generate-ip",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Randomly generate, format, and validate IPv4
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "Randomly generate, format, and validate IPv4 + IPv6 + MAC addresses.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
7
7
|
"email": "adam@kudoai.com",
|
|
8
8
|
"url": "https://github.com/adamlui"
|
|
9
9
|
},
|
|
10
|
-
"homepage": "https://
|
|
10
|
+
"homepage": "https://generate-ip.org",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"main": "dist/generate-ip.min.js",
|
|
13
13
|
"files": [
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"url": "https://github.com/sponsors/adamlui"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@adamlui/minify.js": "^1.5.
|
|
59
|
+
"@adamlui/minify.js": "^1.5.8"
|
|
60
60
|
}
|
|
61
61
|
}
|