@lsby/cloudflare-ipv6-ddns 0.0.6 → 0.0.8

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 +14 -11
  2. package/package.json +2 -2
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记录...');
@@ -24,9 +33,6 @@ async function 增加或更新dns记录(cf句柄, 区域id, 域名, ip地址,
24
33
  console.log('没有找到域名%O对应的记录, 将新增该记录...', 域名);
25
34
  await cf句柄.dns.records.create({
26
35
  zone_id: 区域id,
27
- // 2024年7月3日 发现参数名称改成了body_zone_id
28
- // @ts-ignore
29
- body_zone_id: 区域id,
30
36
  content: ip地址,
31
37
  name: 域名,
32
38
  proxied: 使用代理,
@@ -47,9 +53,6 @@ async function 增加或更新dns记录(cf句柄, 区域id, 域名, ip地址,
47
53
  console.log('找到域名%O对应的记录, 发现ip有变化, 将修改该记录', 域名);
48
54
  await cf句柄.dns.records.edit(目标.id, {
49
55
  zone_id: 区域id,
50
- // 2024年7月3日 发现参数名称改成了body_zone_id
51
- // @ts-ignore
52
- body_zone_id: 区域id,
53
56
  content: ip地址,
54
57
  name: 域名,
55
58
  // 截至 2024年5月2日, 接口实际返回的值包括proxiable和proxied, proxiable总为true, 所以这里使用proxied.
@@ -76,4 +79,4 @@ async function main() {
76
79
  const ipv6地址 = await 获取IPv6地址();
77
80
  await 增加或更新dns记录(cloudflare, 区域id, 域名, ipv6地址, 'AAAA');
78
81
  }
79
- await main().catch(console.log);
82
+ // await main().catch(console.log)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsby/cloudflare-ipv6-ddns",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "lsby-cloudflare-ipv6-ddns": "dist/index.js"
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "axios": "^1.6.8",
13
- "cloudflare": "^3.1.0",
13
+ "cloudflare": "3.1.0",
14
14
  "dotenv": "^16.4.5"
15
15
  },
16
16
  "devDependencies": {