@lsby/cloudflare-ipv6-ddns 0.0.10 → 0.0.11

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.
Files changed (2) hide show
  1. package/dist/index.js +24 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2,16 +2,32 @@
2
2
  import { execSync } from 'child_process';
3
3
  import Cloudflare from 'cloudflare';
4
4
  import dotenv from 'dotenv';
5
+ import { axios请求 } from './tools/axios.js';
5
6
  async function 获取IPv6地址() {
6
7
  console.log('开始获取本机ipv6地址...');
7
- // try {
8
- // const 响应 = await axios请求<{ ip: string }>({ method: 'GET', url: 'https://api6.ipify.org/?format=json' })
9
- // console.log('成功获取本机ipv6地址: %O', 响应.ip)
10
- // return 响应.ip
11
- // } catch (网络错误) {
12
- // console.log(网络错误)
13
- // }
14
- // console.log('无法通过网络获取ipv6地址,尝试调用系统接口...')
8
+ try {
9
+ console.log('使用 test.ipw.cn');
10
+ const 响应 = await axios请求({
11
+ method: 'GET',
12
+ url: 'https://test.ipw.cn/api/ip/myip?json',
13
+ });
14
+ if (响应.IPVersion == 'IPv6')
15
+ console.log('成功获取本机ipv6地址: %O', 响应.IPVersion);
16
+ return 响应.IP;
17
+ }
18
+ catch (网络错误) {
19
+ console.log(网络错误);
20
+ }
21
+ try {
22
+ console.log('使用 api6.ipify.org');
23
+ const 响应 = await axios请求({ method: 'GET', url: 'https://api6.ipify.org/?format=json' });
24
+ console.log('成功获取本机ipv6地址: %O', 响应.ip);
25
+ return 响应.ip;
26
+ }
27
+ catch (网络错误) {
28
+ console.log(网络错误);
29
+ }
30
+ console.log('无法通过网络获取ipv6地址,尝试调用系统接口...');
15
31
  const 结果 = execSync("ip -6 addr show | grep inet6 | awk '{print $2}' | cut -d/ -f1 | grep -v '::1' | head -n 1")
16
32
  .toString()
17
33
  .trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsby/cloudflare-ipv6-ddns",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "lsby-cloudflare-ipv6-ddns": "dist/index.js"