@lsby/cloudflare-ipv6-ddns 0.0.7 → 0.0.9

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 +13 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,18 +1,27 @@
1
1
  #!/usr/bin/env node
2
+ import { execSync } from 'child_process';
2
3
  import Cloudflare from 'cloudflare';
3
4
  import dotenv from 'dotenv';
4
5
  import { axios请求 } from './tools/axios.js';
5
6
  async function 获取IPv6地址() {
7
+ console.log('开始获取本机ipv6地址...');
6
8
  try {
7
- console.log('开始获取本机ipv6地址...');
8
9
  const 响应 = await axios请求({ method: 'GET', url: 'https://api6.ipify.org/?format=json' });
9
10
  console.log('成功获取本机ipv6地址: %O', 响应.ip);
10
11
  return 响应.ip;
11
12
  }
12
- catch (e) {
13
- console.log('无法获得ipv6地址');
14
- throw e;
13
+ catch (网络错误) {
14
+ console.log(网络错误);
15
15
  }
16
+ console.log('无法通过网络获取ipv6地址,尝试调用系统接口...');
17
+ const 结果 = execSync("ip -6 addr show | grep inet6 | awk '{print $2}' | cut -d/ -f1 | grep -v '::1' | head -n 1")
18
+ .toString()
19
+ .trim();
20
+ if (结果) {
21
+ console.log('成功获取本机ipv6地址: %O', 结果);
22
+ return 结果;
23
+ }
24
+ throw new Error('无法获得ipv6地址');
16
25
  }
17
26
  async function 增加或更新dns记录(cf句柄, 区域id, 域名, ip地址, 类型, 使用代理 = false, ttl = 1) {
18
27
  console.log('开始增加或修改dns记录...');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsby/cloudflare-ipv6-ddns",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "lsby-cloudflare-ipv6-ddns": "dist/index.js"