-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.js
executable file
·47 lines (41 loc) · 891 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
import meow from 'meow';
import {publicIpv4, publicIpv6} from 'public-ip';
const cli = meow(`
Usage
$ public-ip
Options
--ipv4, -4 Return the IPv4 address (default)
--ipv6, -6 Return the IPv6 address
--https, -h Use HTTPS instead of DNS
--timeout=<ms>, -t Timeout in milliseconds (default: 5000)
Example
$ public-ip
46.5.21.123
`, {
importMeta: import.meta,
flags: {
ipv4: {
type: 'boolean',
shortFlag: '4',
},
ipv6: {
type: 'boolean',
shortFlag: '6',
},
https: {
type: 'boolean',
shortFlag: 'h',
},
timeout: {
type: 'string',
shortFlag: 't',
},
},
});
const getIp = cli.flags.ipv6 ? publicIpv6 : publicIpv4;
const ip = await getIp({
https: cli.flags.https ? true : undefined,
timeout: cli.flags.timeout !== undefined && Number(cli.flags.timeout),
});
console.log(ip);