feat: 添加IPv6地址获取功能,优化Cloudflare DNS记录更新逻辑,更新版本号并添加README

This commit is contained in:
2026-04-12 01:09:04 +08:00
parent 3581d8cf96
commit 45b6f138e1
7 changed files with 92 additions and 16 deletions

View File

@@ -8,6 +8,14 @@ const baseURLv6 = 'https://6.ipw.cn/';
// https://api.ipify.org/?format=text
// https://ipinfo.io/ip
import { app } from './app.ts';
import { exec } from 'child_process';
import { promisify } from 'util';
const execAsync = promisify(exec);
const curl6 = async (url: string): Promise<string> => {
const { stdout } = await execAsync(`curl -6 -s "${url}"`);
return stdout.trim();
};
app.route({
path: 'ip',
@@ -29,15 +37,11 @@ app.route({
}).define(async (ctx) => {
let ip = ''
try {
const response = await fetch(baseURLv6);
ip = (await response.text()).trim();
} catch (error) {
}
ip = await curl6(baseURLv6);
} catch (error) { }
if (!isIpv6(ip)) {
try {
const response2 = await fetch('https://ifconfig.co/ip');
ip = (await response2.text()).trim();
ip = await curl6('https://ifconfig.co/ip');
console.log('尝试第二个接口获取IPv6地址:', ip);
} catch (error) { }
}