Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
862717a47e | ||
|
|
88984719c5 | ||
|
|
684292de76 | ||
|
|
293157b3f8 | ||
|
|
d6fdf67bc9 | ||
|
|
3449babbe0 | ||
|
|
ba0286bd07 | ||
|
|
e3d5eb0200 | ||
|
|
dbaf6a0da9 |
No files matched your search
@@ -25,3 +25,6 @@ docs/.vitepress/*.timestamp-*
|
||||
tmp/
|
||||
setting.json
|
||||
*.BIN
|
||||
|
||||
# 本地调试脚本与实测产物(不入库,与 ipw-boce 的约定一致)
|
||||
tmp-smoke/
|
||||
@@ -224,7 +224,7 @@ systemctl restart lemon-ipw
|
||||
|
||||
节点无论是否接入 WS,都会上报自身版本与支持的管理能力:
|
||||
|
||||
- **版本号**来自构建时注入的 `VERSION`,随 WS `register` 报文上报(字段 `version`);纯 HTTP 节点(无 WS 连接)由收集中心探活 `GET /` 时一并取回(响应体含 `version`)。
|
||||
- **版本号**来自构建时注入的 `VERSION`,随 WS `register` 报文上报(字段 `version`);纯 HTTP 主节点(无 WS 连接)由收集中心探活后再请求 `GET /info` 取回(`GET /` 只返回 `{"status":"ok"}`)。边缘函数版本不提供 `/info`。
|
||||
- **能力清单**(`capabilities`)取值为 `probe` / `report` / `config` / `ota`,用于让收集中心在下发管理指令前判断该节点能否理解——老版本节点的消息循环没有对应分支,收到管理消息会**静默忽略**,只能靠超时暴露。
|
||||
- 收集中心「节点状态」页展示每个节点的版本号,并据此判断哪些节点需要升级;节点升级部署后重新注册即为新版本。
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
| 通道 | 鉴权方式 | 未配置凭据时 |
|
||||
|------|----------|--------------|
|
||||
| 业务探测 `/v1/*` | `access-token` 非空时校验 `Authorization: Bearer <access-token>`,不符返回 `401` | 不启用鉴权,公开可访问 |
|
||||
| 健康检查 `/` | 无 | — |
|
||||
| 健康检查 `/`、节点信息 `/info` | 无 | — |
|
||||
| 管理接口 `/v1/config`、`/v1/ota`(HTTP) | 同业务接口,复用 `tokenCheck` | **整组关闭**,一律返回 `403`(节点未配 `access-token` 时业务接口本身也无鉴权,暴露配置读写等于公网可改配置) |
|
||||
| WS 通道 | 中间件 `ws-keys` 校验注册报文 | WS **常开**:节点是客户端,指令只来自已通过中间件校验的连接,与节点是否配 `access-token` 无关 |
|
||||
|
||||
@@ -17,13 +17,19 @@
|
||||
|
||||
---
|
||||
|
||||
## 一、健康检查
|
||||
## 一、健康检查与节点信息
|
||||
|
||||
```
|
||||
GET / → {"status":"ok","version":"v1.2.3","capabilities":["probe","report","config","ota"]}
|
||||
GET / → {"status":"ok"}
|
||||
GET /info → {"version":"v1.2.3","capabilities":["probe","report","config","ota"]}
|
||||
```
|
||||
|
||||
无鉴权、不计入统计。除存活外同时回报**版本号**与**能力清单**:收集中心对纯 HTTP 节点(无 WS 连接)探活时一并取回,用于节点状态页展示版本、以及下发管理指令前判断该节点能否理解对应指令。
|
||||
两个端点都无鉴权、不计入统计,且都注册在 `/v1` 组之外——因此既不受 `access-token` 约束,也不经过业务统计中间件。
|
||||
|
||||
- **健康检查 `/`**:只回答"进程是否活着"。给负载均衡、OTA 就绪探测(`otaWaitChildReady`)与运维 `curl` 用。**不回报版本**:它是免鉴权的对外端点,回版本号等于向公网公开节点版本。
|
||||
- **节点信息 `/info`**:回报节点身份。`version` 为版本号,`capabilities` 为能力清单(与 WS `register` 报文同源,见 `ws.go nodeCapabilities`)。收集中心对纯 HTTP 节点(无 WS 连接)探活后单独取回,用于节点状态页展示版本、以及下发管理指令前判断该节点能否理解对应指令。
|
||||
|
||||
> 老版本节点没有 `/info`(返回 `404`),边缘函数版节点同样不提供;收集中心取不到就留空,不影响判活。
|
||||
|
||||
---
|
||||
|
||||
@@ -174,7 +180,7 @@ POST /v1/ota
|
||||
|
||||
## 六、能力清单(capabilities)
|
||||
|
||||
节点在 `register` 报文与 `GET /` 中上报自身支持的管理能力,取值为 `probe` / `report` / `config` / `ota` 的数组。
|
||||
节点在 `register` 报文与主节点的 `GET /info` 中上报自身支持的管理能力,取值为 `probe` / `report` / `config` / `ota` 的数组。边缘函数版本不提供 `/info`,也不回报能力清单。
|
||||
|
||||
收集中心据此做**三态判定**,绝不能把"未知"当作"不支持":
|
||||
|
||||
|
||||
@@ -31,5 +31,5 @@ features:
|
||||
- title: 远程运维
|
||||
details: 节点上报版本号与能力清单,收集中心展示版本、远程读写运行时配置,并可下发一次性 OTA 升级任务(下载 → 校验 → 替换 → 重启,失败自动回滚)。
|
||||
- title: 多平台部署
|
||||
details: 支持二进制,Docker,乃至AWS Lambda,EdgeOne Makers,Vercel和阿里云函数计算
|
||||
details: 支持二进制、Docker,以及 EdgeOne Makers 和 Vercel 部署
|
||||
---
|
||||
@@ -74,6 +74,6 @@
|
||||
|------|------|
|
||||
| 二进制 / systemd | `install.sh` 一键安装,配置以环境变量注入 |
|
||||
| Docker | `src/Dockerfile` 多阶段构建,多架构(amd64 / arm64 / armv7);镜像不含 IP 库,首次运行现场拉取 |
|
||||
| Serverless | EdgeOne Makers、Vercel、AWS Lambda、阿里云函数计算等(均为 IPv4-only,需声明 `SINGLE_STACK=ipv4`) |
|
||||
| Serverless | EdgeOne Go 边缘函数、Vercel 部署入口(仓库提供实现;均为 IPv4-only,需声明 `SINGLE_STACK=ipv4`) |
|
||||
|
||||
各形态的详细步骤见 [后端节点部署](/guide/deploy-node)。
|
||||
@@ -32,7 +32,7 @@ Lemon IPW(柠檬味 ipw.cn 替代品)是一个开源的分布式站点测试
|
||||
- 后端(Go)提供全部检测 API,可在任意地区部署测试节点,是分布式查询的核心
|
||||
- 独立中间件(middleware-go)使用Fiber技术栈 负责请求转发和 Key 注入
|
||||
|
||||
后端支持二进制、Docker 自托管,也支持 AWS Lambda、EdgeOne Makers、Vercel、阿里云函数计算等 Serverless 平台部署。
|
||||
后端支持二进制、Docker 自托管,以及仓库中提供的 EdgeOne Go 边缘函数和对应的 Vercel 部署入口。AWS Lambda、阿里云函数计算目前没有对应的实现或部署配置。
|
||||
|
||||
## 技术栈
|
||||
|
||||
|
||||
@@ -11,6 +11,12 @@ const drawer = ref(false);
|
||||
const isDark = useDark();
|
||||
const toggleDark = useToggle(isDark);
|
||||
|
||||
// ==================== 抽屉里的文档菜单 ====================
|
||||
// 窄屏下 /doc 页面自己的左侧侧栏会被隐藏(见 app/pages/doc/*.vue),
|
||||
// 文档导航改由这里的抽屉承载;宽屏不渲染抽屉,一切照旧。
|
||||
const route = useRoute()
|
||||
const isDocRoute = computed(() => route.path === '/doc' || route.path.startsWith('/doc/'))
|
||||
|
||||
function cleanChineseCharacters(str:string) {
|
||||
return str.replace(/[\u4e00-\u9fa5]/g, '');
|
||||
}
|
||||
@@ -129,7 +135,7 @@ onMounted(() => {
|
||||
|
||||
<template>
|
||||
|
||||
<el-drawer v-if="isNarrow" v-model="drawer" direction="ltr" style="height: 100%;" size="50%">
|
||||
<el-drawer v-if="isNarrow" v-model="drawer" direction="ltr" style="height: 100%;" :size="isDocRoute ? '80%' : '60%'">
|
||||
<router-link to="/ipv6webcheck">
|
||||
<p class="menu-item-text">IPv6 网站检测</p>
|
||||
</router-link>
|
||||
@@ -150,16 +156,33 @@ onMounted(() => {
|
||||
<router-link to="/whois"><p class="menu-item-text">Whois查询</p></router-link>
|
||||
<router-link to="/asn"><p class="menu-item-text">ASN查询</p></router-link>
|
||||
<router-link to="/dnssec"><p class="menu-item-text">DNSSEC验证</p></router-link>
|
||||
<!-- 窄屏唯一的文档入口:非文档页面抽屉里不挂整份文档菜单(太长),
|
||||
只留这一个链接,对应宽屏顶栏 index 9 的「文档」项。
|
||||
进入文档页后,抽屉里才会出现完整的文档导航。 -->
|
||||
<router-link v-if="!isDocRoute" to="/doc" @click="drawer = false"><p class="menu-item-text">文档</p></router-link>
|
||||
<!-- 文档导航并进同一个左侧菜单:与 /doc 页面用的是同一个组件。
|
||||
只在文档路由下出现(非文档页面抽屉里就只留工具链接);
|
||||
文档路由下分组默认展开(手机上没 hover,省一次点击)。
|
||||
:key 是为了让分组开合重新初始化 —— el-menu 只在挂载时读一次 default-openeds,
|
||||
抽屉一旦打开过就不会重挂,不加 key 会停在首次打开时的开合状态。 -->
|
||||
<DocMenu
|
||||
v-if="isDocRoute"
|
||||
:key="'doc-expanded'"
|
||||
expand-all
|
||||
@select="drawer = false"
|
||||
/>
|
||||
</el-drawer>
|
||||
<el-menu
|
||||
mode="horizontal"
|
||||
:ellipsis="false"
|
||||
|
||||
>
|
||||
<el-menu-item index="0">
|
||||
<el-menu-item index="0" aria-label="返回首页">
|
||||
<el-icon v-if="isNarrow" @click="drawer = !drawer"><Expand /></el-icon>
|
||||
<router-link to="/">
|
||||
<el-image src="/favicon.svg" style="margin-top: 20px;" />
|
||||
<router-link to="/" aria-label="返回首页">
|
||||
<!-- alt 留空是有意的:logo 属装饰图,可访问名由外层链接提供。
|
||||
若把 alt 写成站名,宽屏下会与旁边的 h2 一起被读两遍。 -->
|
||||
<el-image src="/favicon.svg" alt="" style="margin-top: 20px;" />
|
||||
<h2 style="display: inline-block; margin-left: 10px" v-if="!isNarrow">{{ config.siteName }}</h2>
|
||||
</router-link>
|
||||
</el-menu-item>
|
||||
@@ -193,7 +216,8 @@ onMounted(() => {
|
||||
</template>
|
||||
</el-sub-menu>
|
||||
</template>
|
||||
<el-menu-item index="10">
|
||||
<!-- 纯图标菜单项:无可访问名,补 aria-label(图标本身不带文字) -->
|
||||
<el-menu-item index="10" aria-label="切换深色/浅色模式">
|
||||
<ClientOnly>
|
||||
<el-icon @click="toggleDark()" v-if="isDark" style="cursor: pointer;"><Moon style="height: 20px; width: 20px;"/></el-icon>
|
||||
<el-icon @click="toggleDark()" v-else style="cursor: pointer;"><Sunny style="height: 20px; width: 20px;"/></el-icon>
|
||||
@@ -208,7 +232,9 @@ onMounted(() => {
|
||||
<NuxtPage />
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<!-- 文档路由不渲染页脚:文档页是阅读页,正文底部加备案/版权块会打断阅读,
|
||||
且窄屏下与侧栏抽屉的可滚动区域互相挤压。 -->
|
||||
<footer v-if="!isDocRoute">
|
||||
<div class="one-line">
|
||||
Copyright © nomdn & IP 查询 2026 | <img src="/ipv6-s1.svg" alt="IPv6 相关标识"/> | <img src="/ssl-s1.svg" alt="SSL 相关标识"/> | All right reserved
|
||||
</div>
|
||||
@@ -216,7 +242,7 @@ onMounted(() => {
|
||||
<a v-if="config.ICP" href="https://beian.miit.gov.cn/" target="_blank" rel="noreferrer" >{{ config.ICP }}</a>
|
||||
<span v-if="config.ICP"> | </span>
|
||||
<el-image v-if="config.GongAn" style="height: 1em; width: 1em;" src="/备案图标.png" />
|
||||
<a :href="'https://beian.mps.gov.cn/#/query/webSearch?code=' + cleanChineseCharacters(config.GongAn)" target="_blank" rel="noreferrer" >{{ config.GongAn }}</a>
|
||||
<a v-if="config.GongAn" :href="'https://beian.mps.gov.cn/#/query/webSearch?code=' + cleanChineseCharacters(config.GongAn)" target="_blank" rel="noreferrer" >{{ config.GongAn }}</a>
|
||||
<span v-if="config.GongAn"> | </span>
|
||||
<a href="https://www.china-ipv6.cn/" target="_blank" rel="noreferrer" >国家IPv6发展监测平台</a>
|
||||
| 请遵守中国法律法规 |
|
||||
@@ -268,31 +294,79 @@ onMounted(() => {
|
||||
--el-color-primary: #3EAF7C;
|
||||
}
|
||||
html.dark {
|
||||
/* 暗色模式下根元素的文字色与页面底色。
|
||||
这两条必须在【非 scoped】块里:<html> 永远不会带上组件 scope 属性,
|
||||
若写在 <style scoped>(含被 scoped @import 进来的 style.css)里,会被改写成
|
||||
`html.dark[data-v-xxxx]` —— 整条规则永不匹配,底色只能靠浏览器的 color-scheme 兜底。 */
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
--el-color-primary: #3EAF7C;
|
||||
}
|
||||
|
||||
/* Drawer 内部链接占满一行 */
|
||||
/* Drawer 内部链接占满一行。
|
||||
注意用直接子选择器(> a):文档菜单(DocMenu)里的 <a> 嵌在 el-menu-item 里,
|
||||
不能被这套「整行大按钮」规则吃掉,否则菜单项会变成上下带 1em 内边距的块。
|
||||
间距三层叠加会挤没文字(body 20px + a 1em + p margin-left 10px),
|
||||
所以 body 归零、a 只留一层、p 的 margin 清掉,字号定死 15px 保证最长的
|
||||
「IPv6/IPv4 地址查询」在 320px 屏的 60% 抽屉里也放得下。 */
|
||||
.el-drawer__body {
|
||||
overflow-x: hidden;
|
||||
padding: 6px 0;
|
||||
font-size: 15px;
|
||||
}
|
||||
.el-drawer__body a {
|
||||
.el-drawer__body > a {
|
||||
display: block !important;
|
||||
width: 100% !important;
|
||||
box-sizing: border-box;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
padding: 1em;
|
||||
padding: 12px 16px;
|
||||
font-size: 15px;
|
||||
}
|
||||
.el-drawer__body a p {
|
||||
.el-drawer__body > a p.menu-item-text {
|
||||
display: block !important;
|
||||
width: 100% !important;
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* 并进抽屉的文档菜单:与上面的工具链接视觉上分段,并去掉菜单自带底色与右边框
|
||||
(.el-menu 默认 border-right,竖排菜单是给页面侧栏用的,在抽屉里会多出一条竖线) */
|
||||
.el-drawer__body .el-menu {
|
||||
background-color: transparent;
|
||||
border-right: none;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
padding-top: 8px;
|
||||
}
|
||||
/* 手机上条目多,行高压到 44px 让一屏能多看几项(默认 56px)。
|
||||
文档标题可能很长(如「Windows 10/11 设置 IPv4/IPv6 访问优先级」),
|
||||
截断会丢信息 → 允许换行,高度改 auto 只保 44px 最小行高。 */
|
||||
/* 手机上条目多,行高压到 44px 让一屏能多看几项(默认 56px)。
|
||||
注意:element-plus 竖排菜单规则是
|
||||
`.el-menu--vertical:not(..)×3 .el-menu-item`(特异性 5 个类),
|
||||
这里必须 !important 才压得住 height / line-height / white-space。
|
||||
文档标题可能很长(如「Windows 10/11 设置 IPv4/IPv6 访问优先级」),
|
||||
截断会丢信息 → 允许换行,高度改 auto 只保 44px 最小行高。 */
|
||||
.el-drawer__body .el-menu .el-menu-item,
|
||||
.el-drawer__body .el-menu .el-sub-menu__title {
|
||||
height: auto !important;
|
||||
min-height: 44px;
|
||||
line-height: 1.45 !important;
|
||||
padding-top: 6px;
|
||||
padding-bottom: 6px;
|
||||
white-space: normal !important; /* 长标题裸文本在 li 上,必须解掉 nowrap */
|
||||
}
|
||||
.el-drawer__body .el-menu .el-menu-item a,
|
||||
.el-drawer__body .el-menu .el-menu-item p {
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* 窄屏(≤768px,与 script 中 isNarrow 的 matchMedia 断点一致):
|
||||
在水合前由 CSS 兜底隐藏宽屏菜单项,避免窄屏设备闪现宽屏布局 */
|
||||
@media (max-width: 768px) {
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 文档导航菜单(全站唯一实现,结构别在别处再抄一份)
|
||||
*
|
||||
* - 宽屏:由 /doc 与 /doc/** 页面直接渲染成左侧固定侧边栏(由页面传 class="sidebar-menu")
|
||||
* - 窄屏:页面那边把侧边栏整个隐藏,改由根布局的左侧抽屉菜单挂同一份本组件,
|
||||
* 这样手机上不需要两个菜单,也不至于没入口进文档。
|
||||
*/
|
||||
const route = useRoute()
|
||||
const activeIndex = computed(() => route.path)
|
||||
|
||||
// 所有可展开分组的 index(含嵌套的「最佳实践」)。
|
||||
// 抽屉里给展开态用:手机上没有 hover,分组默认收着的话用户还得先点开一层才能看到目的地。
|
||||
const ALL_GROUPS = [
|
||||
'IPv6 用户端',
|
||||
'最佳实践',
|
||||
'云服务器配置 IPv6',
|
||||
'IPv6 协议规范',
|
||||
'API 接口',
|
||||
]
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
/** true = 所有分组初始展开(抽屉用);false = 保持 element-plus 默认的收起态(页面侧栏用) */
|
||||
expandAll?: boolean
|
||||
}>(), { expandAll: false })
|
||||
|
||||
// undefined 让 element-plus 走自己的默认值,宽屏下行为与改造前完全一致
|
||||
const openeds = computed(() => (props.expandAll ? ALL_GROUPS : undefined))
|
||||
|
||||
const emit = defineEmits<{ select: [index: string] }>()
|
||||
</script>
|
||||
<template>
|
||||
<el-menu
|
||||
:default-active="activeIndex"
|
||||
:default-openeds="openeds"
|
||||
router
|
||||
@select="(index: string) => emit('select', index)"
|
||||
>
|
||||
<!-- 1. 独立菜单项 -->
|
||||
<el-menu-item index="/doc">
|
||||
<span>IPv6 工具箱使用文档</span>
|
||||
</el-menu-item>
|
||||
|
||||
<!-- 2. IPv6 用户端 -->
|
||||
<el-sub-menu index="IPv6 用户端">
|
||||
<template #title>
|
||||
<span>IPv6 用户端</span>
|
||||
</template>
|
||||
|
||||
<el-menu-item index="/doc/user/enable_ipv6">个人宽带如何开启IPv6网络访问</el-menu-item>
|
||||
<el-menu-item index="/doc/user/cmd_bash_disable_ipv6">命令行禁用/启用IPv6本地网络</el-menu-item>
|
||||
<el-menu-item index="/doc/user/cmd_getip">命令行(curl)获取 IPv4 和 IPv6 地址</el-menu-item>
|
||||
<el-menu-item index="/doc/user/view_ipv6_adress_url">浏览器访问 IPv6 地址</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv4_ipv6_prefix_precedence">Windows 10/11 设置 IPv4/IPv6 访问优先级</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv6_daohang">国内 IPv6 资源导航</el-menu-item>
|
||||
<el-menu-item index="/doc/user/pure_ipv6_website">国内纯 IPv6 网站导航</el-menu-item>
|
||||
<el-menu-item index="/doc/user/dns">全国各省 DNS 服务器列表</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv6_dns">IPv6 DNS 地址列表</el-menu-item>
|
||||
<el-menu-item index="/doc/user/code_getip">Python/Go 获取 IPv4 和 IPv6 地址</el-menu-item>
|
||||
<el-menu-item index="/doc/user/dns_dig">DNS 解析流程</el-menu-item>
|
||||
|
||||
<!-- 嵌套子菜单:最佳实践 -->
|
||||
<el-sub-menu index="最佳实践">
|
||||
<template #title>
|
||||
<span>最佳实践</span>
|
||||
</template>
|
||||
<el-menu-item index="/doc/user/AliyunAuthorizeSecurityGroup">阿里云自动化添加安全组</el-menu-item>
|
||||
<el-menu-item index="/doc/user/TencentCloudAddSecurityGroup">腾讯云自动化添加安全组</el-menu-item>
|
||||
</el-sub-menu>
|
||||
</el-sub-menu>
|
||||
|
||||
<!-- 3. 云服务器配置 IPv6 -->
|
||||
<el-sub-menu index="云服务器配置 IPv6">
|
||||
<template #title>
|
||||
<span>云服务器配置 IPv6</span>
|
||||
</template>
|
||||
<el-menu-item index="/doc/server/website_enable_ipv6">网站开启 IPv6 的三种方式</el-menu-item>
|
||||
<el-menu-item index="/doc/server/tencent_cloud_cvm_ipv6">腾讯云 cvm 开启 IPv6</el-menu-item>
|
||||
<el-menu-item index="/doc/server/nginx_ipv6">Nginx 开启 IPv6</el-menu-item>
|
||||
<el-menu-item index="/doc/server/ipv6webcheck">如何确认一个网站是否开启 IPv6</el-menu-item>
|
||||
<el-menu-item index="/doc/server/ipv6_sign">网站增加支持IPv6访问标识</el-menu-item>
|
||||
<el-menu-item index="/doc/server/ipv6_domain_record">如何为域名添加 IPv6 解析记录</el-menu-item>
|
||||
<el-menu-item index="/doc/server/http2">网站如何开启 HTTP/2</el-menu-item>
|
||||
<el-menu-item index="/doc/server/check_userip_ipv4_ipv6">JS 检查网络是 IPv4 还是 IPv6</el-menu-item>
|
||||
<el-menu-item index="/doc/server/tls">网站如何开启 TLS</el-menu-item>
|
||||
</el-sub-menu>
|
||||
|
||||
<!-- 4. IPv6 协议规范 -->
|
||||
<el-sub-menu index="IPv6 协议规范">
|
||||
<template #title>
|
||||
<span>IPv6 协议规范</span>
|
||||
</template>
|
||||
<el-menu-item index="/doc/rfc/rfc8200">IPv6 RFC8200 解读</el-menu-item>
|
||||
<el-menu-item index="/doc/rfc/ipv6_address_format">IPv6 地址标识方法</el-menu-item>
|
||||
<el-menu-item index="/doc/user/tcpdump_ipv6">tcpdump 分析IPv6包</el-menu-item>
|
||||
<el-menu-item index="/doc/user/wireshark_ipv6">WireShark 分析IPv6包头</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv6_ping">IPv6 Ping 原理</el-menu-item>
|
||||
</el-sub-menu>
|
||||
|
||||
<!-- 5. API 接口 -->
|
||||
<el-sub-menu index="API 接口">
|
||||
<template #title>
|
||||
<span>API 接口</span>
|
||||
</template>
|
||||
<el-menu-item index="/doc/api/ip/locate">获取客户端公网 IP 及位置</el-menu-item>
|
||||
<el-menu-item index="/doc/api/ip/myip">获取客户端公网 IP 地址</el-menu-item>
|
||||
<el-menu-item index="/doc/api/ip/query">查询指定 IP 地址的位置信息</el-menu-item>
|
||||
<el-menu-item index="/doc/api/whois/query">查询域名的 WHOIS 信息</el-menu-item>
|
||||
</el-sub-menu>
|
||||
</el-menu>
|
||||
</template>
|
||||
@@ -157,6 +157,16 @@ async function queryDNS() {
|
||||
}
|
||||
|
||||
|
||||
// 行内「数据格是否该渲染」判定。
|
||||
//
|
||||
// 结果表共 6 列(服务器 / 类型 / 记录 / 记录数 / 耗时 / TTL);后三列(记录数、耗时、TTL)
|
||||
// 只在真正拿到结果时才有意义。加载中与失败两种状态由「记录」那格用 colspan=4 横跨到表尾,
|
||||
// 若此时再渲染后三格,整行就会变成 2+4+3=9 格 —— 表格按最大列数排版,凭空多出 3 列,
|
||||
// 表头只剩 6 列、右侧留出空档,错误行也跟着错位。
|
||||
function hasData(result: any) {
|
||||
return !result?.loading && !result?.error
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
const domainParam = route.query.domain as string
|
||||
@@ -242,9 +252,11 @@ const doc = page.value;
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td class="table-value" v-if="!result.loading">{{result.data?.record?.length || 0}}</td>
|
||||
<td class="table-value" v-if="!result.loading">{{formatTime(result.data?.duration)}}</td>
|
||||
<td class="table-value" v-if="!result.loading">{{result.data?.ttl}}</td>
|
||||
<!-- 后三格必须与「记录」格的 colspan 互斥:加载中/失败时该格已跨满到表尾,
|
||||
这里再渲染就会多出 3 列(见 hasData 注释) -->
|
||||
<td class="table-value" v-if="hasData(result)">{{result.data?.record?.length || 0}}</td>
|
||||
<td class="table-value" v-if="hasData(result)">{{formatTime(result.data?.duration)}}</td>
|
||||
<td class="table-value" v-if="hasData(result)">{{result.data?.ttl}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ const route = useRoute();
|
||||
|
||||
const path = computed(() => route.path)
|
||||
const { data: page } = await useFetch(() => `/api/markdown${path.value}`)
|
||||
const activeIndex = computed(() => route.path)
|
||||
|
||||
const meta = computed(() => getDocMeta(route.path))
|
||||
useHead({
|
||||
@@ -17,69 +16,9 @@ useHead({
|
||||
</script>
|
||||
<template>
|
||||
<div class="box">
|
||||
<el-menu
|
||||
:default-active="activeIndex"
|
||||
class="sidebar-menu"
|
||||
router
|
||||
>
|
||||
<!-- 1. 独立菜单项 -->
|
||||
<el-menu-item index="/doc">
|
||||
<span>IPv6 工具箱使用文档</span>
|
||||
</el-menu-item>
|
||||
|
||||
<!-- 2. IPv6 用户端 -->
|
||||
<el-sub-menu index="IPv6 用户端">
|
||||
<template #title>
|
||||
<span>IPv6 用户端</span>
|
||||
</template>
|
||||
|
||||
<el-menu-item index="/doc/user/enable_ipv6">个人宽带如何开启IPv6网络访问</el-menu-item>
|
||||
<el-menu-item index="/doc/user/cmd_bash_disable_ipv6">命令行禁用/启用IPv6本地网络</el-menu-item>
|
||||
<el-menu-item index="/doc/user/cmd_getip">命令行(curl)获取 IPv4 和 IPv6 地址</el-menu-item>
|
||||
<el-menu-item index="/doc/user/view_ipv6_adress_url">浏览器访问 IPv6 地址</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv4_ipv6_prefix_precedence">Windows 10/11 设置 IPv4/IPv6 访问优先级</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv6_daohang">国内 IPv6 资源导航</el-menu-item>
|
||||
<el-menu-item index="/doc/user/pure_ipv6_website">国内纯 IPv6 网站导航</el-menu-item>
|
||||
<el-menu-item index="/doc/user/dns">全国各省 DNS 服务器列表</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv6_dns">IPv6 DNS 地址列表</el-menu-item>
|
||||
|
||||
<!-- 嵌套子菜单:最佳实践 -->
|
||||
<el-sub-menu index="最佳实践">
|
||||
<template #title>
|
||||
<span>最佳实践</span>
|
||||
</template>
|
||||
<el-menu-item index="/doc/user/AliyunAuthorizeSecurityGroup">阿里云自动化添加安全组</el-menu-item>
|
||||
<el-menu-item index="/doc/user/TencentCloudAddSecurityGroup">腾讯云自动化添加安全组</el-menu-item>
|
||||
</el-sub-menu>
|
||||
</el-sub-menu>
|
||||
|
||||
<!-- 3. 云服务器配置 IPv6 -->
|
||||
<el-sub-menu index="云服务器配置 IPv6">
|
||||
<template #title>
|
||||
<span>云服务器配置 IPv6</span>
|
||||
</template>
|
||||
<el-menu-item index="/doc/server/website_enable_ipv6">网站开启 IPv6 的三种方式</el-menu-item>
|
||||
<el-menu-item index="/doc/server/tencent_cloud_cvm_ipv6">腾讯云 cvm 开启 IPv6</el-menu-item>
|
||||
<el-menu-item index="/doc/server/nginx_ipv6">Nginx 开启 IPv6</el-menu-item>
|
||||
<el-menu-item index="/doc/server/ipv6webcheck">如何确认一个网站是否开启 IPv6</el-menu-item>
|
||||
<el-menu-item index="/doc/server/ipv6_sign">网站增加支持IPv6访问标识</el-menu-item>
|
||||
<el-menu-item index="/doc/server/ipv6_domain_record">如何为域名添加 IPv6 解析记录</el-menu-item>
|
||||
<el-menu-item index="/doc/server/http2">网站如何开启 HTTP/2</el-menu-item>
|
||||
</el-sub-menu>
|
||||
|
||||
<!-- 4. IPv6 协议规范 -->
|
||||
<el-sub-menu index="IPv6 协议规范">
|
||||
<template #title>
|
||||
<span>IPv6 协议规范</span>
|
||||
</template>
|
||||
<el-menu-item index="/doc/rfc/rfc8200">IPv6 RFC8200 解读</el-menu-item>
|
||||
<el-menu-item index="/doc/rfc/ipv6_address_format">IPv6 地址标识方法</el-menu-item>
|
||||
<el-menu-item index="/doc/user/tcpdump_ipv6">tcpdump 分析IPv6包</el-menu-item>
|
||||
<el-menu-item index="/doc/user/wireshark_ipv6">WireShark 分析IPv6包头</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv6_ping">IPv6 Ping 原理</el-menu-item>
|
||||
</el-sub-menu>
|
||||
|
||||
</el-menu>
|
||||
<!-- 文档导航只有一份实现(app/components/DocMenu.vue)。
|
||||
宽屏:就是这条左侧固定侧栏;窄屏:本侧栏隐藏,改由顶部抽屉菜单承载 -->
|
||||
<DocMenu class="sidebar-menu" />
|
||||
<div class="content">
|
||||
<div class="markdown-body" v-if="page">
|
||||
<div v-html="page" />
|
||||
@@ -119,8 +58,10 @@ html.dark .content {
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
/* 窄屏不再挤一条窄侧栏(原先 100px,长标题全被截断):
|
||||
文档导航已并入左侧抽屉菜单,这里直接撤掉,正文铺满整屏 */
|
||||
.sidebar-menu {
|
||||
width: 100px;
|
||||
display: none;
|
||||
}
|
||||
.content {
|
||||
padding: 10px;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { getDocMeta } from '../../../config/doc'
|
||||
|
||||
const route = useRoute();
|
||||
const { data: page } = await useAsyncData('doc-index', () =>
|
||||
$fetch('/api/markdown/doc/index')
|
||||
)
|
||||
const doc = page.value;
|
||||
const activeIndex = computed(() => route.path)
|
||||
|
||||
const meta = getDocMeta('/doc')
|
||||
useHead({
|
||||
@@ -18,69 +16,9 @@ useHead({
|
||||
</script>
|
||||
<template>
|
||||
<div class="box">
|
||||
<el-menu
|
||||
:default-active="activeIndex"
|
||||
class="sidebar-menu"
|
||||
router
|
||||
>
|
||||
<!-- 1. 独立菜单项 -->
|
||||
<el-menu-item index="/doc">
|
||||
<span>IPv6 工具箱使用文档</span>
|
||||
</el-menu-item>
|
||||
|
||||
<!-- 2. IPv6 用户端 -->
|
||||
<el-sub-menu index="IPv6 用户端">
|
||||
<template #title>
|
||||
<span>IPv6 用户端</span>
|
||||
</template>
|
||||
|
||||
<el-menu-item index="/doc/user/enable_ipv6">个人宽带如何开启IPv6网络访问</el-menu-item>
|
||||
<el-menu-item index="/doc/user/cmd_bash_disable_ipv6">命令行禁用/启用IPv6本地网络</el-menu-item>
|
||||
<el-menu-item index="/doc/user/cmd_getip">命令行(curl)获取 IPv4 和 IPv6 地址</el-menu-item>
|
||||
<el-menu-item index="/doc/user/view_ipv6_adress_url">浏览器访问 IPv6 地址</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv4_ipv6_prefix_precedence">Windows 10/11 设置 IPv4/IPv6 访问优先级</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv6_daohang">国内 IPv6 资源导航</el-menu-item>
|
||||
<el-menu-item index="/doc/user/pure_ipv6_website">国内纯 IPv6 网站导航</el-menu-item>
|
||||
<el-menu-item index="/doc/user/dns">全国各省 DNS 服务器列表</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv6_dns">IPv6 DNS 地址列表</el-menu-item>
|
||||
|
||||
<!-- 嵌套子菜单:最佳实践 -->
|
||||
<el-sub-menu index="最佳实践">
|
||||
<template #title>
|
||||
<span>最佳实践</span>
|
||||
</template>
|
||||
<el-menu-item index="/doc/user/AliyunAuthorizeSecurityGroup">阿里云自动化添加安全组</el-menu-item>
|
||||
<el-menu-item index="/doc/user/TencentCloudAddSecurityGroup">腾讯云自动化添加安全组</el-menu-item>
|
||||
</el-sub-menu>
|
||||
</el-sub-menu>
|
||||
|
||||
<!-- 3. 云服务器配置 IPv6 -->
|
||||
<el-sub-menu index="云服务器配置 IPv6">
|
||||
<template #title>
|
||||
<span>云服务器配置 IPv6</span>
|
||||
</template>
|
||||
<el-menu-item index="/doc/server/website_enable_ipv6">网站开启 IPv6 的三种方式</el-menu-item>
|
||||
<el-menu-item index="/doc/server/tencent_cloud_cvm_ipv6">腾讯云 cvm 开启 IPv6</el-menu-item>
|
||||
<el-menu-item index="/doc/server/nginx_ipv6">Nginx 开启 IPv6</el-menu-item>
|
||||
<el-menu-item index="/doc/server/ipv6webcheck">如何确认一个网站是否开启 IPv6</el-menu-item>
|
||||
<el-menu-item index="/doc/server/ipv6_sign">网站增加支持IPv6访问标识</el-menu-item>
|
||||
<el-menu-item index="/doc/server/ipv6_domain_record">如何为域名添加 IPv6 解析记录</el-menu-item>
|
||||
<el-menu-item index="/doc/server/http2">网站如何开启 HTTP/2</el-menu-item>
|
||||
</el-sub-menu>
|
||||
|
||||
<!-- 4. IPv6 协议规范 -->
|
||||
<el-sub-menu index="IPv6 协议规范">
|
||||
<template #title>
|
||||
<span>IPv6 协议规范</span>
|
||||
</template>
|
||||
<el-menu-item index="/doc/rfc/rfc8200">IPv6 RFC8200 解读</el-menu-item>
|
||||
<el-menu-item index="/doc/rfc/ipv6_address_format">IPv6 地址标识方法</el-menu-item>
|
||||
<el-menu-item index="/doc/user/tcpdump_ipv6">tcpdump 分析IPv6包</el-menu-item>
|
||||
<el-menu-item index="/doc/user/wireshark_ipv6">WireShark 分析IPv6包头</el-menu-item>
|
||||
<el-menu-item index="/doc/user/ipv6_ping">IPv6 Ping 原理</el-menu-item>
|
||||
</el-sub-menu>
|
||||
|
||||
</el-menu>
|
||||
<!-- 文档导航只有一份实现(app/components/DocMenu.vue)。
|
||||
宽屏:就是这条左侧固定侧栏;窄屏:本侧栏隐藏,改由顶部抽屉菜单承载 -->
|
||||
<DocMenu class="sidebar-menu" />
|
||||
<div class="content">
|
||||
<div class="markdown-body" v-html="doc"></div>
|
||||
</div>
|
||||
@@ -118,8 +56,10 @@ html.dark .content {
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
/* 窄屏不再挤一条窄侧栏(原先 100px,长标题全被截断):
|
||||
文档导航已并入左侧抽屉菜单,这里直接撤掉,正文铺满整屏 */
|
||||
.sidebar-menu {
|
||||
width: 100px;
|
||||
display: none;
|
||||
}
|
||||
.content {
|
||||
padding: 10px;
|
||||
|
||||
@@ -3,7 +3,6 @@ import { computed, ref, onMounted } from 'vue';
|
||||
import { isIPv6 } from 'is-ip';
|
||||
import { config } from '../../config/index';
|
||||
import { CircleCheckFilled, CircleCloseFilled } from '@element-plus/icons-vue';
|
||||
import { highlightCode } from '../../utils/shiki';
|
||||
import { isIPv4 } from '../../utils/tools';
|
||||
const route = useRoute();
|
||||
const canonicalUrl = computed(() => new URL(route.path, config.siteUrl).toString());
|
||||
@@ -81,28 +80,50 @@ const ipAddress = ref('');
|
||||
const yourIPv4 = ref('');
|
||||
const yourIPv6 = ref('');
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
highlightedCode.value = await highlightCode(code, 'bash');
|
||||
} catch {
|
||||
highlightedCode.value = '';
|
||||
}
|
||||
onMounted(() => {
|
||||
// 代码高亮与三个 IP 查询互不依赖,一起发出即可。
|
||||
// 注意别写成"先 await 高亮再发请求":shiki 首次要把语言包拉下来,会把三次查询整体推后数百毫秒。
|
||||
//
|
||||
// 用动态 import 而非顶层静态 import:shiki 的引擎核心 + 语言/主题注册表约 160KB,
|
||||
// 首页只为这 4 行 curl 示例需要它。静态 import 会把它拽进首屏同步加载的关键路径
|
||||
// (构建后体现为一个 164KB 的 chunk 出现在 modulepreload 列表);动态 import 后
|
||||
// 它单独成 chunk,首屏渲染不再等它。
|
||||
void import('../../utils/shiki')
|
||||
.then(({ highlightCode }) => highlightCode(code, 'bash'))
|
||||
.then((html) => {
|
||||
highlightedCode.value = html;
|
||||
})
|
||||
.catch(() => {
|
||||
highlightedCode.value = '';
|
||||
});
|
||||
|
||||
const [dualStack, ipV4, ipV6] = await Promise.allSettled([
|
||||
$fetch<string>(config.DualStackAPI),
|
||||
$fetch<string>(config.v4OnlyAPI),
|
||||
$fetch<string>(config.v6OnlyAPI)
|
||||
]);
|
||||
// 三个地址各自独立请求、各自渲染:谁先回来谁先上屏。
|
||||
// 不用 Promise.allSettled 包起来等齐——那样只要有一个慢(例如纯 IPv4 网络下 v6 接口要等超时),
|
||||
// 已经拿到的 IPv4 与双栈结果也得一起干等。
|
||||
//
|
||||
// retry: false —— ofetch 默认会对 GET 重发一次:网络层失败时它拿不到 response,就按 500 计
|
||||
// (500 在默认重试白名单里),且默认延迟为 0,立即重发。于是"这个节点连不上"会被原样重做一遍,
|
||||
// 用户白等一倍时间(实测 ofetch 1.5.1:裸调用触发 2 次真实 fetch,传 retry:false 后只剩 1 次;
|
||||
// 浏览器自身不会重试,底层 fetch 对同一请求只被调用过一次)。
|
||||
const ipFetchOptions = { retry: false } as const;
|
||||
|
||||
if (dualStack.status === 'fulfilled') {
|
||||
ipAddress.value = dualStack.value;
|
||||
}
|
||||
if (ipV4.status === 'fulfilled') {
|
||||
yourIPv4.value = ipV4.value;
|
||||
}
|
||||
if (ipV6.status === 'fulfilled') {
|
||||
yourIPv6.value = ipV6.value;
|
||||
}
|
||||
$fetch<string>(config.DualStackAPI, ipFetchOptions)
|
||||
.then((ip) => {
|
||||
ipAddress.value = ip;
|
||||
})
|
||||
.catch(() => {
|
||||
// 单个接口失败不影响其它两行展示,保持"查询中"占位
|
||||
});
|
||||
$fetch<string>(config.v4OnlyAPI, ipFetchOptions)
|
||||
.then((ip) => {
|
||||
yourIPv4.value = ip;
|
||||
})
|
||||
.catch(() => {});
|
||||
$fetch<string>(config.v6OnlyAPI, ipFetchOptions)
|
||||
.then((ip) => {
|
||||
yourIPv6.value = ip;
|
||||
})
|
||||
.catch(() => {});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -121,10 +142,10 @@ onMounted(async () => {
|
||||
<div class="one-line">
|
||||
<b>IPv6</b> <p v-if="yourIPv6">{{ yourIPv6 }}</p><RouterLink :to="`/location?ip=${yourIPv6}`" target="_blank" v-if="yourIPv6"> 查询归属地</RouterLink><RouterLink v-else to="/doc/user/enable_ipv6" target="_blank">没有IPv6地址,查看如何开启IPv6</RouterLink>
|
||||
</div>
|
||||
<div style="font-size: 1.5em;">
|
||||
<h3 v-if="ipAddress && isIPv6(ipAddress)"><el-icon><CircleCheckFilled style="color: lightgreen;"/></el-icon>您的网络IPv6优先</h3>
|
||||
<h3 v-else-if="ipAddress && isIPv4(ipAddress)"><el-icon><CircleCloseFilled style="color: red;"/></el-icon>您的网络IPv4优先</h3>
|
||||
<h3 v-else><el-icon><CircleCloseFilled /></el-icon>查询中,请稍后</h3>
|
||||
<div class="ip-priority">
|
||||
<h2 v-if="ipAddress && isIPv6(ipAddress)"><el-icon><CircleCheckFilled style="color: lightgreen;"/></el-icon>您的网络IPv6优先</h2>
|
||||
<h2 v-else-if="ipAddress && isIPv4(ipAddress)"><el-icon><CircleCloseFilled style="color: red;"/></el-icon>您的网络IPv4优先</h2>
|
||||
<h2 v-else><el-icon><CircleCloseFilled /></el-icon>查询中,请稍后</h2>
|
||||
</div>
|
||||
<blockquote>
|
||||
手机默认开启 IPv6,宽带开启 IPv6 请参阅<a href="/doc/user/enable_ipv6" target="_blank">文档</a>
|
||||
@@ -141,6 +162,17 @@ onMounted(async () => {
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
/* 网络优先级提示:原来是「div 1.5em × h3」,但 h1 之后直跳 h3 违反标题层级(heading-order),
|
||||
语义上应为 h2。style.css 给 h3 显式定了 1.3em / 窄屏 1.1em,h2 只有 1.5em 一档,
|
||||
所以这里把字号按原样补回,避免语义修正顺带改了视觉(含 margin:UA 的 h3 是 1em,h2 是 0.83em)。 */
|
||||
.ip-priority {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
.ip-priority h2 {
|
||||
font-size: 1.3em;
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
.code-block {
|
||||
margin-top: 1rem;
|
||||
padding: 1rem;
|
||||
@@ -159,6 +191,9 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.ip-priority h2 {
|
||||
font-size: 1.1em;
|
||||
}
|
||||
.code-block {
|
||||
padding: 0.75rem;
|
||||
font-size: 0.8em;
|
||||
|
||||
@@ -5,7 +5,6 @@ import {config} from '../../config/index';
|
||||
import { useMiddlewareFetch } from '../../utils/middleware';
|
||||
import { CircleCheckFilled, CircleCloseFilled } from '@element-plus/icons-vue';
|
||||
import { useRoute } from 'vue-router'
|
||||
import { highlightCode } from '../../utils/shiki'
|
||||
import { isIPv4 } from '../../utils/tools';
|
||||
const route = useRoute();
|
||||
const loading = ref(false);
|
||||
@@ -118,7 +117,19 @@ function locateIP(IP: string){
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
html.value = await highlightCode(code, 'bash')
|
||||
// 代码高亮与下面的「取本机 IP / 定位查询」互不依赖,别把它摆在流程最前面 await ——
|
||||
// 否则后面那次 $fetch 要等 160KB 的 shiki 下载完才会发出。
|
||||
// 动态 import 让 shiki(引擎 + 语言/主题注册表)单独成 chunk,首屏渲染不再等它。
|
||||
void import('../../utils/shiki')
|
||||
.then(({ highlightCode }) => highlightCode(code, 'bash'))
|
||||
.then((h) => {
|
||||
html.value = h
|
||||
})
|
||||
.catch(() => {
|
||||
// 连 import 本身都失败时退回原始代码,别让代码块空着
|
||||
html.value = code
|
||||
})
|
||||
|
||||
const urlParam = route.query.ip;
|
||||
if (urlParam) {
|
||||
ipAddress.value = urlParam as string;
|
||||
|
||||
@@ -108,8 +108,9 @@ blockquote p {
|
||||
blockquote a{
|
||||
color: #3EAF7C;
|
||||
font-size: 1em;
|
||||
text-decoration: none
|
||||
|
||||
/* 正文里的链接仅靠颜色区分不够(绿 #3EAF7C 与周围正文的对比度远低于 3:1),
|
||||
补下划线提供「非颜色」的视觉区分(link-in-text-block) */
|
||||
text-decoration: underline
|
||||
}
|
||||
a {
|
||||
color: #3EAF7C;
|
||||
@@ -205,15 +206,15 @@ footer {
|
||||
|
||||
color: #3EAF7C;
|
||||
font-size: 1em;
|
||||
text-decoration: none
|
||||
/* 与上面的非窄屏规则保持一致:窄屏同样靠下划线做非颜色区分。
|
||||
此处若仍写 none,因其位置在后、特异性相同,会把桌面的 underline 盖掉。 */
|
||||
text-decoration: underline
|
||||
}
|
||||
}
|
||||
html.dark {
|
||||
/* 在暗色模式下,覆盖根元素的文字颜色和背景色 */
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
--el-color-primary: #3EAF7C;
|
||||
}
|
||||
/* 注:暗色模式的「根元素」规则(html.dark 的文字色 / 背景色 / 主色变量)已上移到
|
||||
app.vue 的【非 scoped】<style> 块。本文件是被 <style scoped> @import 进来的,
|
||||
凡是作用于 <html> 自身的规则都会被加上 scope 属性而永不匹配。
|
||||
这里只保留作用于「html 后代元素」的规则(后代元素带 scope 属性,能正常命中)。 */
|
||||
html.dark blockquote {
|
||||
/* 在暗色模式下,覆盖根元素的文字颜色和背景色 */
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
|
||||
@@ -6,99 +6,131 @@ export interface DocMeta {
|
||||
export const docConfig: Record<string, DocMeta> = {
|
||||
'/doc': {
|
||||
title: 'IPv6 工具箱使用文档',
|
||||
description: 'IPv6 工具箱使用文档'
|
||||
description: '致力于普及 IPv6,推进 IPv6 规模部署和应用,以全面推进 IPv6 技术创新与融合应用为主线,以提升应用广度深度为主攻方向。支持 IPv6 本地网络(宽带)开启验证、IPv6 网站开启检测、IPv6 Ping 延迟测试、IPv6 网站测速、IPv6 地址查询、IPv6 DNS 解析。'
|
||||
},
|
||||
'/doc/user/enable_ipv6': {
|
||||
title: '个人宽带如何开启IPv6网络访问',
|
||||
description: '介绍个人宽带如何开启IPv6网络访问'
|
||||
description: 'IPv6 是大势所趋,就在前段时间湖南联通发布公告,对家庭宽带提供 IPv6 地址,不再提供 IPv4 地址,那本文就介绍个人宽带如何开启 IPv6 网络访问。'
|
||||
},
|
||||
'/doc/user/cmd_bash_disable_ipv6': {
|
||||
title: '命令行禁用/启用IPv6本地网络',
|
||||
description: 'macOS和Window10命令行禁用/启用IPv6本地网络'
|
||||
description: '图形化禁用 IPv6 网络比较繁琐,以下是 macOS 和 Window 10 命令行下禁用/启用 IPv6 本地网络的方法。'
|
||||
},
|
||||
'/doc/user/cmd_getip': {
|
||||
title: '命令行(curl)获取 IPv4 和 IPv6 地址',
|
||||
description: '使用命令行curl获取IPv4和IPv6地址'
|
||||
description: '通过 curl 命令获取公网 IPv4 和 IPv6 地址,还可以返回是 IPv4 还是 IPv6 访问优先。'
|
||||
},
|
||||
'/doc/user/view_ipv6_adress_url': {
|
||||
title: '浏览器访问 IPv6 地址',
|
||||
description: '如何在浏览器中访问IPv6地址'
|
||||
description: '在 IPv6 地址两边加上中括号,就可以通过浏览器访问了,比如 http://[2402:4e00:1013:e500:0:9671:f018:4947]/'
|
||||
},
|
||||
'/doc/user/ipv4_ipv6_prefix_precedence': {
|
||||
title: 'Windows 10/11 设置 IPv4/IPv6 访问优先级',
|
||||
description: 'Windows 10/11 设置 IPv4/IPv6 访问优先级'
|
||||
description: 'Windows 10/11 开启 IPv6 后默认 IPv6 访问优先(以访问 IPv4/IPv6 双栈站点为例,操作系统会优先访问 IPv6),如果期望 IPv4 访问优先,可以通过 netsh 命令调整。'
|
||||
},
|
||||
'/doc/user/ipv6_daohang': {
|
||||
title: '国内 IPv6 资源导航',
|
||||
description: '国内IPv6资源导航列表'
|
||||
description: 'IPv6 网络开启成功后,可以访问一些 IPv6 网站资源,来体验下 IPv6 的魅力。不过目前纯 IPv6 网站比较少,目前网站支持 IPv6 的主流方式为 IPv4/IPv6 双栈访问,毕竟要兼顾 IPv4 网络用户的访问需求。'
|
||||
},
|
||||
'/doc/user/pure_ipv6_website': {
|
||||
title: '国内纯 IPv6 网站导航',
|
||||
description: '国内纯IPv6网站导航列表'
|
||||
description: 'IPv6 网络开启成功后,可以访问一些纯 IPv6 网站资源,来体验下 IPv6 的魅力。'
|
||||
},
|
||||
'/doc/user/dns': {
|
||||
title: '全国各省 DNS 服务器列表',
|
||||
description: '全国各省DNS服务器列表'
|
||||
description: '全国各省电信、联通、移动的首选 IPv4 DNS 服务器和备用 DNS 服务器,以及公共 DNS 服务器列表,最近更新为 2021-07-25。'
|
||||
},
|
||||
'/doc/user/ipv6_dns': {
|
||||
title: 'IPv6 DNS 地址列表',
|
||||
description: 'IPv6 DNS地址列表'
|
||||
description: 'IPv6 DNS 地址列表,请求 IPv6 网络需要设置 IPv6 DNS。'
|
||||
},
|
||||
'/doc/user/AliyunAuthorizeSecurityGroup': {
|
||||
title: '阿里云自动化添加安全组',
|
||||
description: '阿里云自动化添加安全组'
|
||||
description: 'Golang 代码实操阿里云自动化添加安全组'
|
||||
},
|
||||
'/doc/user/TencentCloudAddSecurityGroup': {
|
||||
title: '腾讯云自动化添加安全组',
|
||||
description: '腾讯云自动化添加安全组'
|
||||
description: 'Golang 代码实操腾讯云自动化添加安全组'
|
||||
},
|
||||
'/doc/server/website_enable_ipv6': {
|
||||
title: '网站开启 IPv6 的三种方式',
|
||||
description: '从传统二进制部署的Nginx,到云原生部署的K8S、Istio,分别介绍网站开启IPv6的三种方式'
|
||||
description: '从传统二进制部署的 Nginx,到云原生部署的 K8S、Istio,分别介绍网站开启 IPv6 的三种方式。'
|
||||
},
|
||||
'/doc/server/tencent_cloud_cvm_ipv6': {
|
||||
title: '腾讯云 cvm 开启 IPv6',
|
||||
description: '一文看懂在腾讯云CVM上开启IPv6,只需7步'
|
||||
description: '一文看懂在腾讯云 CVM 上开启 IPv6,只需 7 步。'
|
||||
},
|
||||
'/doc/server/nginx_ipv6': {
|
||||
title: 'Nginx 开启 IPv6',
|
||||
description: '一文看懂Nginx中开启IPv6,包含设置IPv6 SSL证书'
|
||||
description: '一文看懂 Nginx 中开启 IPv6,包含设置 IPv6 SSL 证书。'
|
||||
},
|
||||
'/doc/server/ipv6webcheck': {
|
||||
title: '如何确认一个网站是否开启 IPv6',
|
||||
description: '如何确认一个网站是否开启IPv6'
|
||||
description: '通过 IPv6 网站检测工具,一键检查网站是否开启 IPv6 访问。'
|
||||
},
|
||||
'/doc/server/ipv6_sign': {
|
||||
title: '网站增加支持IPv6访问标识',
|
||||
description: 'HTML+CSS代码,可以提醒访客本网站支持IPv6访问'
|
||||
description: 'HTML+CSS 代码,可以提醒访客本网站支持 IPv6 访问,同时可以跳转到 IPv6 网站检测页面。'
|
||||
},
|
||||
'/doc/server/ipv6_domain_record': {
|
||||
title: '如何为域名添加 IPv6 解析记录',
|
||||
description: '如何为域名添加IPv6解析记录'
|
||||
description: 'IPv6 网站准备好了后,接下来可以为网站域名添加 IPv6 解析记录(AAAA)。'
|
||||
},
|
||||
'/doc/server/http2': {
|
||||
title: '原创网站如何开启 HTTP/2',
|
||||
description: '介绍网站如何开启HTTP/2协议'
|
||||
title: '网站如何开启 HTTP/2',
|
||||
description: 'HTTP/2 通过引入字段压缩和允许在同一连接上进行多个并发交换,使网络资源得到更有效的利用,并减少了延迟。'
|
||||
},
|
||||
'/doc/rfc/rfc8200': {
|
||||
title: 'IPv6 RFC8200 解读',
|
||||
description: 'RFC8200(Internet Protocol, Version 6 (IPv6) Specification) 是IPv6的权威定义'
|
||||
description: 'RFC8200(Internet Protocol, Version 6 (IPv6) Specification)是 IPv6 的权威定义,接下来在解读 RFC8200 文档中的过程中,加深对 IPv6 的理解。'
|
||||
},
|
||||
'/doc/rfc/ipv6_address_format': {
|
||||
title: 'IPv6 地址标识方法',
|
||||
description: '首选格式、压缩格式、内嵌IPv4地址的IPv6地址格式'
|
||||
description: '首选格式、压缩格式、内嵌 IPv4 地址的 IPv6 地址格式。'
|
||||
},
|
||||
'/doc/user/tcpdump_ipv6': {
|
||||
title: 'tcpdump 分析IPv6包',
|
||||
description: '使用tcpdump分析IPv6包'
|
||||
title: 'tcpdump 分析 IPv6 包',
|
||||
description: 'tcpdump 分析 IPv6 包'
|
||||
},
|
||||
'/doc/user/wireshark_ipv6': {
|
||||
title: 'WireShark 分析IPv6包头',
|
||||
description: '使用WireShark分析IPv6包头'
|
||||
description: '使用 WireShark 分析 IPv6 包头'
|
||||
},
|
||||
'/doc/user/ipv6_ping': {
|
||||
title: 'IPv6 Ping 检测原理',
|
||||
description: 'IPv6 Ping检测原理'
|
||||
description: '协议标准:Internet Control Message Protocol (ICMPv6) for the Internet Protocol Version 6 (IPv6) Specification'
|
||||
},
|
||||
'/doc/api/ip/locate': {
|
||||
title: '获取客户端公网 IP 及位置',
|
||||
description: '调用本项目的 /v1/location 接口,一次取回访问者自己的公网 IP 与 10 套 IP 库的归属地结果。'
|
||||
},
|
||||
'/doc/api/ip/myip': {
|
||||
title: '获取客户端公网 IP 地址',
|
||||
description: '用自带边缘函数获取客户端公网 IP,纯文本返回、支持跨域,可按 IPv4 / IPv6 / 双栈分别部署。'
|
||||
},
|
||||
'/doc/api/ip/query': {
|
||||
title: '查询指定 IP 地址的位置信息',
|
||||
description: '调用本项目的 /v1/location/<ip> 接口查询任意 IPv4 / IPv6 地址的归属地,返回多源聚合结果。'
|
||||
},
|
||||
'/doc/api/whois/query': {
|
||||
title: '查询域名的 WHOIS 信息',
|
||||
description: '调用本项目的 /v1/whois/<domain> 接口查询域名注册信息:IANA → 注册局 → 注册商转介三跳,返回状态、注册商、关键日期与 NS。'
|
||||
},
|
||||
'/doc/server/check_userip_ipv4_ipv6': {
|
||||
title: 'JS 检查网络是 IPv4 还是 IPv6',
|
||||
description: '通过 JS 代码检查客户端是 IPv4 还是 IPv6 访问优先。'
|
||||
},
|
||||
'/doc/server/tls': {
|
||||
title: '网站如何开启 TLS',
|
||||
description: '用 Wireshark 抓包分析 TLS 1.3 的 TCP 三次握手与 TLS 协商全过程。'
|
||||
},
|
||||
'/doc/user/code_getip': {
|
||||
title: 'Python/Go 获取 IPv4 和 IPv6 地址',
|
||||
description: '通过 Python/Golang 获取公网 IPv4 和 IPv6 地址,还可以返回是 IPv4 还是 IPv6 访问优先。'
|
||||
},
|
||||
'/doc/user/dns_dig': {
|
||||
title: 'DNS 解析流程',
|
||||
description: '剖析 DNS 解析流程'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,11 +43,11 @@ const config = {
|
||||
id: "cn-jiangsu",
|
||||
url: "https://cn-jiangsu.api-ipw.wsmdn.top/"
|
||||
},
|
||||
{
|
||||
label: "中国 湖北 武汉 电信",
|
||||
id: "cn-wuhan-chinatelecom",
|
||||
url: ""
|
||||
},
|
||||
// {
|
||||
// label: "中国 湖北 武汉 电信",
|
||||
// id: "cn-wuhan-chinatelecom",
|
||||
// url: ""
|
||||
// },
|
||||
{
|
||||
label: "中国 四川 沙渠 电信[ZFC]",
|
||||
id: "cn2-sichuan",
|
||||
@@ -105,12 +105,12 @@ const config = {
|
||||
id: "hongkong",
|
||||
url: ""
|
||||
},
|
||||
// WS 通道节点:URL 留空,拨测经中间件 WS 转发
|
||||
{
|
||||
label: "呼和浩特移动",
|
||||
id: "2faa15e6-18a7-4355-b422-ca53277d8d77",
|
||||
url: ""
|
||||
}
|
||||
// // WS 通道节点:URL 留空,拨测经中间件 WS 转发
|
||||
// {
|
||||
// label: "呼和浩特移动",
|
||||
// id: "2faa15e6-18a7-4355-b422-ca53277d8d77",
|
||||
// url: ""
|
||||
// }
|
||||
],
|
||||
DualStack: [
|
||||
|
||||
@@ -124,11 +124,11 @@ const config = {
|
||||
id: "cn-shenzhen",
|
||||
url: "https://cn-shenzhen.api-ipw.wsmdn.top/"
|
||||
},
|
||||
{
|
||||
label: "中国 湖北 武汉 电信",
|
||||
id: "cn-wuhan-chinatelecom",
|
||||
url: ""
|
||||
},
|
||||
// {
|
||||
// label: "中国 湖北 武汉 电信",
|
||||
// id: "cn-wuhan-chinatelecom",
|
||||
// url: ""
|
||||
// },
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ export default defineNuxtConfig({
|
||||
include: [
|
||||
'is-ip',
|
||||
'shiki',
|
||||
'dayjs',
|
||||
'lodash-unified'
|
||||
]
|
||||
},
|
||||
},
|
||||
@@ -33,15 +35,22 @@ export default defineNuxtConfig({
|
||||
url: config.siteUrl,
|
||||
name: 'Lemon IPW'
|
||||
},
|
||||
// Element Plus 样式走按需引入:@element-plus/nuxt 默认 importStyle: 'css',
|
||||
// 模板里用到的每个组件都会各自带上 `element-plus/es/components/<组件>/style/css`
|
||||
// (其内部再链到 theme-chalk/base.css,`:root` 的 --el-* 变量就在那里定义)。
|
||||
// 所以这里**不要**再引 element-plus/dist/index.css —— 那是整库样式(原始 360KB),
|
||||
// 而首页实测 98% 的规则用不到,却全压在关键路径上。
|
||||
css: [
|
||||
// 1. 引入 Element Plus 基础样式 (如果你还没有引入的话)
|
||||
'element-plus/dist/index.css',
|
||||
|
||||
// 2. 🌟 关键:引入 Element Plus 官方的暗黑模式 CSS 变量文件
|
||||
// 暗黑模式的 CSS 变量覆盖(html.dark 下的 --el-* 值),按需引入不含它,必须显式引
|
||||
'element-plus/theme-chalk/dark/css-vars.css',
|
||||
],
|
||||
app:{
|
||||
head: {
|
||||
// 站点内容为简体中文。不写时 Nuxt 输出的就是裸 <html>,
|
||||
// 屏幕阅读器会按系统语言瞎猜发音,Lighthouse 的 html-has-lang 也会失败。
|
||||
htmlAttrs: {
|
||||
lang: 'zh-CN',
|
||||
},
|
||||
script: [
|
||||
{
|
||||
// 必须 innerHTML,不能 src(否则异步加载)
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
"@tailwindcss/vite": "^4.3.3",
|
||||
"@vueuse/core": "^14.4.0",
|
||||
"@vueuse/nuxt": "^14.4.0",
|
||||
"better-sqlite3": "^12.11.1",
|
||||
"element-plus": "^2.14.3",
|
||||
"github-markdown-css": "^5.9.0",
|
||||
"github-slugger": "^2.0.0",
|
||||
|
||||
@@ -41,9 +41,6 @@ importers:
|
||||
'@vueuse/nuxt':
|
||||
specifier: ^14.4.0
|
||||
version: 14.4.0(magic-string@1.1.0)(magicast@0.5.4)(nuxt@4.5.1(@babel/plugin-syntax-jsx@7.29.7(@babel/core@7.29.7(supports-color@10.0.0)))(@babel/plugin-syntax-typescript@7.29.7(@babel/core@7.29.7(supports-color@10.0.0)))(@oxc-project/types@0.142.0)(@parcel/watcher@2.5.6)(@vue/compiler-sfc@3.5.40)(better-sqlite3@12.11.1)(db0@0.3.4(better-sqlite3@12.11.1))(esbuild@0.28.1)(ioredis@5.11.1(supports-color@10.0.0))(lightningcss@1.33.0)(magicast@0.5.4)(oxc-parser@0.140.0)(rollup-plugin-visualizer@7.0.1(rolldown@1.2.1)(rollup@4.62.4))(rollup@4.62.4)(sass-embedded@1.100.0)(sass@1.100.0)(srvx@0.11.22)(supports-color@10.0.0)(terser@5.49.0)(typescript@5.9.3)(vite@8.2.0(esbuild@0.28.1)(jiti@2.7.0)(sass-embedded@1.100.0)(sass@1.100.0)(terser@5.49.0)(yaml@2.9.0))(yaml@2.9.0))(oxc-parser@0.140.0)(rolldown@1.2.1)(unplugin@3.3.0(esbuild@0.28.1)(rolldown@1.2.1)(rollup@4.62.4)(vite@8.2.0(esbuild@0.28.1)(jiti@2.7.0)(sass-embedded@1.100.0)(sass@1.100.0)(terser@5.49.0)(yaml@2.9.0)))(vue@3.5.40(typescript@5.9.3))
|
||||
better-sqlite3:
|
||||
specifier: ^12.11.1
|
||||
version: 12.11.1
|
||||
element-plus:
|
||||
specifier: ^2.14.3
|
||||
version: 2.14.3(vue@3.5.40(typescript@5.9.3))
|
||||
@@ -7358,6 +7355,7 @@ snapshots:
|
||||
dependencies:
|
||||
bindings: 1.5.0
|
||||
prebuild-install: 7.1.3
|
||||
optional: true
|
||||
|
||||
binary-extensions@2.3.0: {}
|
||||
|
||||
@@ -7374,6 +7372,7 @@ snapshots:
|
||||
buffer: 5.7.1
|
||||
inherits: 2.0.4
|
||||
readable-stream: 3.6.2
|
||||
optional: true
|
||||
|
||||
blake3-wasm@2.1.5: {}
|
||||
|
||||
@@ -7412,6 +7411,7 @@ snapshots:
|
||||
dependencies:
|
||||
base64-js: 1.5.1
|
||||
ieee754: 1.2.1
|
||||
optional: true
|
||||
|
||||
buffer@6.0.3:
|
||||
dependencies:
|
||||
@@ -7494,7 +7494,8 @@ snapshots:
|
||||
dependencies:
|
||||
readdirp: 5.0.0
|
||||
|
||||
chownr@1.1.4: {}
|
||||
chownr@1.1.4:
|
||||
optional: true
|
||||
|
||||
chownr@3.0.0: {}
|
||||
|
||||
@@ -7704,10 +7705,12 @@ snapshots:
|
||||
decompress-response@6.0.0:
|
||||
dependencies:
|
||||
mimic-response: 3.1.0
|
||||
optional: true
|
||||
|
||||
deep-equal@1.0.1: {}
|
||||
|
||||
deep-extend@0.6.0: {}
|
||||
deep-extend@0.6.0:
|
||||
optional: true
|
||||
|
||||
deepmerge@4.3.1: {}
|
||||
|
||||
@@ -7840,6 +7843,7 @@ snapshots:
|
||||
end-of-stream@1.4.5:
|
||||
dependencies:
|
||||
once: 1.4.0
|
||||
optional: true
|
||||
|
||||
enhanced-resolve@5.24.5:
|
||||
dependencies:
|
||||
@@ -7931,7 +7935,8 @@ snapshots:
|
||||
signal-exit: 4.1.0
|
||||
strip-final-newline: 3.0.0
|
||||
|
||||
expand-template@2.0.3: {}
|
||||
expand-template@2.0.3:
|
||||
optional: true
|
||||
|
||||
exsolve@1.1.1: {}
|
||||
|
||||
@@ -8003,7 +8008,8 @@ snapshots:
|
||||
|
||||
fresh@2.0.0: {}
|
||||
|
||||
fs-constants@1.0.0: {}
|
||||
fs-constants@1.0.0:
|
||||
optional: true
|
||||
|
||||
fs-extra@9.0.1:
|
||||
dependencies:
|
||||
@@ -8061,7 +8067,8 @@ snapshots:
|
||||
|
||||
giget@3.3.1: {}
|
||||
|
||||
github-from-package@0.0.0: {}
|
||||
github-from-package@0.0.0:
|
||||
optional: true
|
||||
|
||||
github-markdown-css@5.9.0: {}
|
||||
|
||||
@@ -8251,7 +8258,8 @@ snapshots:
|
||||
|
||||
inherits@2.0.4: {}
|
||||
|
||||
ini@1.3.0: {}
|
||||
ini@1.3.0:
|
||||
optional: true
|
||||
|
||||
ini@4.1.1: {}
|
||||
|
||||
@@ -8724,7 +8732,8 @@ snapshots:
|
||||
|
||||
mimic-fn@4.0.0: {}
|
||||
|
||||
mimic-response@3.1.0: {}
|
||||
mimic-response@3.1.0:
|
||||
optional: true
|
||||
|
||||
miniflare@5.20260730.0-alpha:
|
||||
dependencies:
|
||||
@@ -8754,7 +8763,8 @@ snapshots:
|
||||
dependencies:
|
||||
brace-expansion: 2.1.4
|
||||
|
||||
minimist@1.2.8: {}
|
||||
minimist@1.2.8:
|
||||
optional: true
|
||||
|
||||
minipass@7.1.3: {}
|
||||
|
||||
@@ -8762,7 +8772,8 @@ snapshots:
|
||||
dependencies:
|
||||
minipass: 7.1.3
|
||||
|
||||
mkdirp-classic@0.5.3: {}
|
||||
mkdirp-classic@0.5.3:
|
||||
optional: true
|
||||
|
||||
mlly@1.8.2:
|
||||
dependencies:
|
||||
@@ -8789,7 +8800,8 @@ snapshots:
|
||||
|
||||
nanotar@0.3.0: {}
|
||||
|
||||
napi-build-utils@2.0.0: {}
|
||||
napi-build-utils@2.0.0:
|
||||
optional: true
|
||||
|
||||
negotiator@0.6.3: {}
|
||||
|
||||
@@ -8914,6 +8926,7 @@ snapshots:
|
||||
node-abi@3.94.0:
|
||||
dependencies:
|
||||
semver: 7.8.5
|
||||
optional: true
|
||||
|
||||
node-addon-api@7.0.0:
|
||||
optional: true
|
||||
@@ -9575,6 +9588,7 @@ snapshots:
|
||||
simple-get: 4.0.1
|
||||
tar-fs: 2.1.5
|
||||
tunnel-agent: 0.6.0
|
||||
optional: true
|
||||
|
||||
pretty-bytes@7.1.1: {}
|
||||
|
||||
@@ -9594,6 +9608,7 @@ snapshots:
|
||||
dependencies:
|
||||
end-of-stream: 1.4.5
|
||||
once: 1.4.0
|
||||
optional: true
|
||||
|
||||
punycode.js@2.3.1: {}
|
||||
|
||||
@@ -9616,6 +9631,7 @@ snapshots:
|
||||
ini: 1.3.0
|
||||
minimist: 1.2.8
|
||||
strip-json-comments: 2.0.1
|
||||
optional: true
|
||||
|
||||
read-cache@1.0.0:
|
||||
dependencies:
|
||||
@@ -9636,6 +9652,7 @@ snapshots:
|
||||
inherits: 2.0.4
|
||||
string_decoder: 1.3.0
|
||||
util-deprecate: 1.0.2
|
||||
optional: true
|
||||
|
||||
readable-stream@4.7.0:
|
||||
dependencies:
|
||||
@@ -9988,13 +10005,15 @@ snapshots:
|
||||
|
||||
signal-exit@4.1.0: {}
|
||||
|
||||
simple-concat@1.0.1: {}
|
||||
simple-concat@1.0.1:
|
||||
optional: true
|
||||
|
||||
simple-get@4.0.1:
|
||||
dependencies:
|
||||
decompress-response: 6.0.0
|
||||
once: 1.4.0
|
||||
simple-concat: 1.0.1
|
||||
optional: true
|
||||
|
||||
simple-git@3.36.0(supports-color@10.0.0):
|
||||
dependencies:
|
||||
@@ -10127,7 +10146,8 @@ snapshots:
|
||||
|
||||
strip-final-newline@3.0.0: {}
|
||||
|
||||
strip-json-comments@2.0.1: {}
|
||||
strip-json-comments@2.0.1:
|
||||
optional: true
|
||||
|
||||
strip-literal@4.0.0:
|
||||
dependencies:
|
||||
@@ -10243,6 +10263,7 @@ snapshots:
|
||||
mkdirp-classic: 0.5.3
|
||||
pump: 3.0.4
|
||||
tar-stream: 2.1.4
|
||||
optional: true
|
||||
|
||||
tar-stream@2.1.4:
|
||||
dependencies:
|
||||
@@ -10251,6 +10272,7 @@ snapshots:
|
||||
fs-constants: 1.0.0
|
||||
inherits: 2.0.4
|
||||
readable-stream: 3.6.2
|
||||
optional: true
|
||||
|
||||
tar-stream@3.2.0:
|
||||
dependencies:
|
||||
@@ -10335,6 +10357,7 @@ snapshots:
|
||||
tunnel-agent@0.6.0:
|
||||
dependencies:
|
||||
safe-buffer: 5.2.1
|
||||
optional: true
|
||||
|
||||
type-fest@5.8.0:
|
||||
dependencies:
|
||||
|
||||
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 718 KiB |
|
After Width: | Height: | Size: 652 KiB |
|
After Width: | Height: | Size: 675 KiB |
|
After Width: | Height: | Size: 635 KiB |
|
After Width: | Height: | Size: 642 KiB |
|
After Width: | Height: | Size: 636 KiB |
|
After Width: | Height: | Size: 622 KiB |
|
After Width: | Height: | Size: 49 KiB |
@@ -2,7 +2,7 @@
|
||||
<svg width="85px" height="36px" viewBox="0 0 85 36" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>ssl-s1</title>
|
||||
<g id="ssl-s1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="ipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<g id="nipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<rect stroke="#07C160" x="0.5" y="0.5" width="74" height="27" rx="5"></rect>
|
||||
<g transform="translate(15.000000, 4.000000)" fill="#07C160">
|
||||
<text id="SSL" font-family="PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans SC, sans-serif" font-size="14" font-weight="500">
|
||||
|
||||
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
@@ -2,7 +2,7 @@
|
||||
<svg width="85px" height="36px" viewBox="0 0 85 36" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>ssl-s2</title>
|
||||
<g id="ssl-s2" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="ipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<g id="nipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<rect stroke="#61BD13" x="0.5" y="0.5" width="74" height="27" rx="5"></rect>
|
||||
<g transform="translate(15.000000, 4.000000)" fill="#61BD13">
|
||||
<text id="SSL" font-family="PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans SC, sans-serif" font-size="14" font-weight="500">
|
||||
|
||||
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
@@ -2,7 +2,7 @@
|
||||
<svg width="85px" height="36px" viewBox="0 0 85 36" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>ssl-s3</title>
|
||||
<g id="ssl-s3" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="ipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<g id="nipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<rect id="矩形备份" stroke="#1A42A0" x="0.5" y="0.5" width="74" height="27" rx="5"></rect>
|
||||
<text id="SSL" font-family="PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans SC, sans-serif" font-size="14" font-weight="500" fill="#1A42A0">
|
||||
<tspan x="34" y="19">SSL</tspan>
|
||||
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
@@ -2,7 +2,7 @@
|
||||
<svg width="85px" height="36px" viewBox="0 0 85 36" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>ssl-s4</title>
|
||||
<g id="ssl-s4" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="ipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<g id="nipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<rect stroke="#3A84FF" x="0.5" y="0.5" width="74" height="27" rx="5"></rect>
|
||||
<g transform="translate(15.000000, 4.000000)" fill="#3A84FF">
|
||||
<text id="SSL" font-family="PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans SC, sans-serif" font-size="14" font-weight="500">
|
||||
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
@@ -2,7 +2,7 @@
|
||||
<svg width="85px" height="36px" viewBox="0 0 85 36" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>ssl-s5</title>
|
||||
<g id="ssl-s5" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="ipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<g id="nipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<rect stroke="#313238" x="0.5" y="0.5" width="74" height="27" rx="5"></rect>
|
||||
<text id="SSL" font-family="PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans SC, sans-serif" font-size="14" font-weight="500" fill="#313238">
|
||||
<tspan x="34" y="19">SSL</tspan>
|
||||
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
@@ -2,7 +2,7 @@
|
||||
<svg width="85px" height="36px" viewBox="0 0 85 36" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>ssl-s6</title>
|
||||
<g id="ssl-s6" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="ipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<g id="nipw.cn" transform="translate(5.000000, 4.000000)">
|
||||
<rect stroke="#757575" x="0.5" y="0.5" width="74" height="27" rx="5"></rect>
|
||||
<text id="SSL" font-family="PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans SC, sans-serif" font-size="14" font-weight="500" fill="#757575">
|
||||
<tspan x="34" y="19">SSL</tspan>
|
||||
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
@@ -0,0 +1,177 @@
|
||||
# [API] 获取客户端公网 IP 及位置
|
||||
|
||||
## 1. 接口描述
|
||||
|
||||
> IP 库来源于网络,本项目不对结果的准确性负责,请在中国法律许可范围内使用.
|
||||
|
||||
接口地址: `https://cn-jiangsu.api-ipw.wsmdn.top/v1/location`(公开实例,见 1.1;换成你自己节点的域名同样可用)
|
||||
|
||||
请求方法:`GET`
|
||||
|
||||
用途:取**请求方自己**的公网 IP,并给出 IP 归属地。
|
||||
|
||||
- **不带参数**:用服务端看到的客户端地址(Go `gin` 的 `ClientIP()`),因此"查自己"只需这一个请求。
|
||||
- **多源聚合,不合并**:返回 10 个 IP 库各自的结论,按源名分组,便于交叉比对;本项目不替你做"以哪个源为准"的判断。
|
||||
- **只查本地库**:不依赖任何第三方在线查询接口(唯一例外是 `bilibili` 源,24 小时缓存)。
|
||||
- **免鉴权**:节点未配 `access-token` 时公开可访问;配了则需带 `Authorization: Bearer <access-token>`。
|
||||
|
||||
> 本接口属于"业务探测"端点,请求会被节点计入统计并周期上报收集中心(不落库明细)。
|
||||
|
||||
### 1.1 公开实例
|
||||
|
||||
本项目对外开放了一个江苏节点,可以直接用它把本接口调通,**无需令牌**:
|
||||
|
||||
| 方式 | 地址 |
|
||||
| --- | --- |
|
||||
| 直连节点(推荐) | `https://cn-jiangsu.api-ipw.wsmdn.top/v1/location` |
|
||||
| 经中间件转发 | **不适用**——中间件路径的最后一段(拨测目标)必须非空,而本接口没有目标参数 |
|
||||
|
||||
> 公共实例是**共享**的,调试与小流量接入没问题,请勿高频轮询、批量抓取,也不要拿它当线上服务的依赖。
|
||||
|
||||
### 1.2 还有别的节点 —— 拨测控制台
|
||||
|
||||
上面的江苏节点只是节点池里的一个。节点池的入口是拨测控制台 <https://boce.wsmdn.top>:
|
||||
登录后进「可用节点」页,能看到**全部已启用节点**的节点标识、归属地、归属池(定位 / 拨测)、
|
||||
协议栈与在线状态,并附上每个节点的调用前缀。
|
||||
|
||||
比自己搭一套省事的地方:
|
||||
|
||||
- **节点现成** —— 名单里的节点都是已经部署好的,不用自己找机器、装程序、配隧道。
|
||||
- **入口现成** —— 统一走 HTTPS 转发,证书与反向代理不用自己操心。
|
||||
- **一套规则调所有节点** —— 接口路径与返回结构完全一致,换节点只换地址。
|
||||
- **池与栈标得很清楚** —— 定位类请求走定位池,拨测类走拨测池,两个池都有的节点两种都能接。
|
||||
- **名单会自己更新** —— 新接入的节点自动出现在列表里,不需要改代码。
|
||||
|
||||
> 本接口("查自己")**只能直连节点**:中间件路径的最后一段必须是拨测目标,而"查自己"没有目标参数,
|
||||
> 所以走中间件转发不适用。换别的节点时,把上例的 `cn-jiangsu.api-ipw.wsmdn.top`
|
||||
> 换成该节点的接入域名即可(节点标识见控制台的「可用节点」页)。
|
||||
>
|
||||
> 节点有上下线,列表中会标出在线状态;离线节点调用会失败。
|
||||
|
||||
## 2. 输入参数
|
||||
|
||||
无。
|
||||
|
||||
## 3. 输出参数
|
||||
|
||||
顶层是「源名 → 该源结果」的字典,另有 `ip` 回显请求方地址:
|
||||
|
||||
| 字段 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| `ip` | String | 请求方公网 IP(本节点视角) |
|
||||
| `ip2region` | Object | `country`/`administrative_area`/`city`(部分记录另带 `isp`) |
|
||||
| `ip2location` | Object | `country`/`country_code`/`administrative_area`/`city`/`district`/`zipcode`/`latitude`/`longitude`/`timezone`/`isp`/`asn`/`usagetype` |
|
||||
| `ip2location_asn` | Object | `asn`/`as` |
|
||||
| `qqwry` | Object | `country`/`country_code`/`administrative_area`/`city`/`isp` |
|
||||
| `maxmind_city` | Object | `country`/`country_code`/`administrative_area`/`city`/`latitude`/`longitude` |
|
||||
| `maxmind_asn` | Object | `asn`/`org` |
|
||||
| `dbip_city` | Object | `country`/`country_code`/`administrative_area`/`city`/`latitude`/`longitude` |
|
||||
| `dbip_asn` | Object | `asn`/`org` |
|
||||
| `geocn` | Object | `division_code`(中国行政区划码)/`administrative_area`/`city`/`isp`/`type` |
|
||||
| `bilibili` | Object | `country`/`administrative_area`/`city`/`isp`/`latitude`/`longitude`(在线源) |
|
||||
|
||||
取值约定:
|
||||
|
||||
- 某源**未加载**时该键为字符串 `"not loaded"`;该源**查询出错**时为字符串 `"error: ..."`。
|
||||
单个源失败**不会**让整个请求失败——HTTP 状态码仍是 `200`。
|
||||
- 库里没有的字段返回空串 `""`。IP2Location LITE 免费版缺失的字段(如 `isp`、`asn`)已统一过滤,不会出现 `"This parameter is unavailable"`。
|
||||
- 经纬度类型各源不一致:`ip2location` 是**字符串**,`maxmind_*` / `dbip_*` 是**数字**;`bilibili` 也是字符串。
|
||||
- ASN 带前缀与否各源不一致:`maxmind_asn` / `dbip_asn` 形如 `AS13335`,`ip2location_asn.asn` 是裸数字 `13335`。
|
||||
|
||||
## 4. 示例
|
||||
|
||||
### 4.1 cURL 获取本机公网 IP 及位置
|
||||
|
||||
```bash
|
||||
curl https://cn-jiangsu.api-ipw.wsmdn.top/v1/location
|
||||
```
|
||||
|
||||
输出示例(节选):
|
||||
|
||||
```json
|
||||
{
|
||||
"ip": "1.1.1.1",
|
||||
"ip2region": { "country": "Australia", "administrative_area": "Queensland", "city": "Brisbane" },
|
||||
"ip2location": {
|
||||
"country": "Australia", "country_code": "AU", "administrative_area": "Queensland",
|
||||
"city": "Brisbane", "zipcode": "4000", "timezone": "+10:00",
|
||||
"latitude": "-27.46754", "longitude": "153.02809"
|
||||
},
|
||||
"maxmind_asn": { "asn": "AS13335", "org": "Cloudflare, Inc." },
|
||||
"dbip_city": {
|
||||
"country": "澳大利亚", "country_code": "AU", "administrative_area": "New South Wales",
|
||||
"city": "Sydney", "latitude": -33.8688, "longitude": 151.209
|
||||
},
|
||||
"qqwry": { "country": "澳大利亚", "country_code": "AU", "administrative_area": "", "city": "", "isp": "APNIC" },
|
||||
"geocn": { "division_code": "0", "isp": "", "type": "" },
|
||||
"bilibili": { "country": "CLOUDFLARE.COM", "administrative_area": "CLOUDFLARE.COM", "city": "", "isp": "" }
|
||||
}
|
||||
```
|
||||
|
||||
### 4.2 Python
|
||||
|
||||
```python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import json
|
||||
import requests
|
||||
|
||||
r = requests.get('https://cn-jiangsu.api-ipw.wsmdn.top/v1/location')
|
||||
data = json.loads(r.text)
|
||||
|
||||
print(data['ip']) # 本机公网 IP
|
||||
print(data['ip2location']['country'],
|
||||
data['ip2location']['administrative_area'],
|
||||
data['ip2location']['city']) # 取某一个源
|
||||
print(data['maxmind_asn']['org']) # 运营商 / 组织
|
||||
```
|
||||
|
||||
### 4.3 Golang
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
resp, err := http.Get("https://cn-jiangsu.api-ipw.wsmdn.top/v1/location")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
|
||||
// 各源字段不一致,逐源取用;此处只解出需要的部分
|
||||
var result map[string]json.RawMessage
|
||||
if err := json.Unmarshal(body, &result); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var ip string
|
||||
_ = json.Unmarshal(result["ip"], &ip)
|
||||
|
||||
var loc struct {
|
||||
Country string `json:"country"`
|
||||
City string `json:"city"`
|
||||
}
|
||||
_ = json.Unmarshal(result["ip2location"], &loc)
|
||||
|
||||
fmt.Println(ip, loc.Country, loc.City)
|
||||
}
|
||||
```
|
||||
|
||||
## 5. 错误码
|
||||
|
||||
| 现象 | 说明 |
|
||||
| --- | --- |
|
||||
| `404 page not found` | 该节点 `ipdb` 已关闭:IP 库不加载时 `/v1/location`、`/v1/asn/:ip` 路由不注册 |
|
||||
| `401` | 节点配了 `access-token` 而未携带正确的 `Authorization: Bearer <access-token>` |
|
||||
| 全部源都是 `"error: ..."` / `"not loaded"` | IP 库仍在下载/加载,或本地库文件缺失。节点启动时自动拉取全套库(首次约 450MB),之后每 24h 更新一次 |
|
||||
| `ip` 是内网地址(如 `10.x`) | 直连节点、未经代理时看到的就是内网地址,属预期 |
|
||||
| `ip` 是代理/CDN 的地址 | 节点前置了 Nginx/CDN 但未配 `trusted-proxies`,`X-Forwarded-For` 不被信任。配置方式见《节点 API 与协议参考》 |
|
||||
@@ -0,0 +1,129 @@
|
||||
# [API] 获取客户端公网 IP 地址
|
||||
|
||||
## 1. 接口描述
|
||||
|
||||
> 该接口用于网络排障,请在中国法律许可范围内使用.
|
||||
|
||||
接口地址: `https://test.wsmdn.top/`(本项目公共实例,双栈;另有仅 IPv4 / 仅 IPv6 的实例,见下文)
|
||||
|
||||
请求方法:`GET`
|
||||
|
||||
用途:**原样**返回访问者的公网 IP——纯文本、无 JSON 包裹、无参数、无鉴权、不查任何 IP 库。
|
||||
|
||||
实现是本项目自带的两个边缘函数(任选其一部署,都只做这一件事):
|
||||
|
||||
| 形态 | 代码 | 取 IP 的方式 |
|
||||
| --- | --- | --- |
|
||||
| Cloudflare Workers | `serverless/lemon-getip` | `CF-Connecting-IP` 请求头 |
|
||||
| EdgeOne Edge Functions | `serverless/edgeone-getip` | `request.eo.clientIp` |
|
||||
|
||||
两者都返回 `content-type: text/plain` 并带 `Access-Control-Allow-Origin: *`,所以浏览器里可以直接跨域取、也可以 `curl`。
|
||||
|
||||
**按协议栈部署三份**,域名的解析记录决定拿到哪一族的地址:
|
||||
|
||||
| 用途 | DNS 记录 | 行为 |
|
||||
| --- | --- | --- |
|
||||
| 双栈 | A + AAAA | 返回客户端**实际使用**的那一族地址 |
|
||||
| 仅 IPv4 | 只配 A | 强制走 v4 出口,返回 IPv4 地址 |
|
||||
| 仅 IPv6 | 只配 AAAA | 纯 IPv6 网络下返回 IPv6 地址;本机没有 IPv6 出口时域名**解析不出来**(请求直接失败,而不是返回空) |
|
||||
|
||||
本项目公共实例即按此部署:`4.wsmdn.top`(仅 IPv4)、`6.wsmdn.top`(仅 IPv6)、`test.wsmdn.top`(双栈)。
|
||||
|
||||
> 想把"本机 IP"和"归属地"一次拿全,用同一套体系里的 `/v1/location`(见「获取客户端公网 IP 及位置」),
|
||||
> 它的 `ip` 字段与这里返回的是同一个地址。江苏节点公开实例:
|
||||
> `curl https://cn-jiangsu.api-ipw.wsmdn.top/v1/location`(无需令牌;该接口没有目标参数,
|
||||
> 只能直连节点,见该页的「公开实例」)。
|
||||
|
||||
## 2. 输入参数
|
||||
|
||||
无。
|
||||
|
||||
## 3. 输出参数
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| 无 | String | 响应体**本身就是**客户端公网 IP 文本,例如 `223.68.219.100` |
|
||||
|
||||
判定要点:
|
||||
|
||||
- 只有 IP 一个 token,没有换行、没有 JSON 包裹;末尾是否带 `\n` 取决于边缘平台,取值前先 `strip()`。
|
||||
- 不查库 ⇒ 不会出现 `"not loaded"` 之类的占位串,也没有归属地信息。
|
||||
- 边缘函数按平台提供的客户端地址取值,**不解析 `X-Forwarded-For`**:它本身就是直接面向公网的入口。若你在它前面又套了一层自建代理,拿到的是代理地址。
|
||||
|
||||
## 4. 示例
|
||||
|
||||
### 4.1 cURL 获取本机公网 IP
|
||||
|
||||
```bash
|
||||
# 双栈(返回实际使用的栈)
|
||||
curl https://test.wsmdn.top
|
||||
|
||||
# 只要 IPv4 / 只要 IPv6
|
||||
curl https://4.wsmdn.top
|
||||
curl https://6.wsmdn.top
|
||||
```
|
||||
|
||||
输出示例:
|
||||
|
||||
```
|
||||
223.68.219.100
|
||||
```
|
||||
|
||||
### 4.2 Python
|
||||
|
||||
```python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import requests
|
||||
|
||||
r = requests.get('https://test.wsmdn.top')
|
||||
clientIP = r.text.strip()
|
||||
|
||||
print(clientIP)
|
||||
```
|
||||
|
||||
### 4.3 Golang
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
resp, err := http.Get("https://test.wsmdn.top")
|
||||
if err != nil {
|
||||
fmt.Println("获取外网 IP 失败,请检查网络")
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
clientIP := strings.TrimSpace(string(body))
|
||||
|
||||
fmt.Println(clientIP)
|
||||
}
|
||||
```
|
||||
|
||||
### 4.4 浏览器里直接取(CORS 已放开)
|
||||
|
||||
```js
|
||||
const ip = await fetch('https://test.wsmdn.top').then(r => r.text())
|
||||
console.log(ip.trim())
|
||||
```
|
||||
|
||||
> 要判断"当前访问更偏向 IPv4 还是 IPv6",可以同时取双栈域名与两个单栈域名做对比,
|
||||
> 思路见「JS 检查网络是 IPv4 还是 IPv6」。
|
||||
|
||||
## 5. 错误码
|
||||
|
||||
| 现象 | 说明 |
|
||||
| --- | --- |
|
||||
| 域名解析失败 / 连接超时 | 用的是**仅 IPv6** 的域名,而本机没有 IPv6 出口。改用双栈或仅 IPv4 的域名 |
|
||||
| 返回 `Unable to determine IP address` | 边缘平台没有提供客户端地址。常见于本地直连调试(`wrangler dev` / EdgeOne 本地调试)或自建前置代理未透传 |
|
||||
| 返回的是代理地址 | 你在边缘函数前面又套了一层代理;该函数只认平台提供的客户端地址,不解析 `X-Forwarded-For` |
|
||||
| 拿到私有地址(如 `192.168.x.x`) | 本地/内网调试环境,边缘平台看到的就是内网出口 |
|
||||
@@ -0,0 +1,189 @@
|
||||
# [API] 查询指定 IP 地址的位置信息
|
||||
|
||||
## 1. 接口描述
|
||||
|
||||
> IP 库来源于网络,本项目不对结果的准确性负责,请在中国法律许可范围内使用.
|
||||
|
||||
接口地址: `https://cn-jiangsu.api-ipw.wsmdn.top/v1/location/<ip>`(公开实例,见 1.1)
|
||||
|
||||
请求方法:`GET`
|
||||
|
||||
用途:查询**任意 IP**(IPv4 或 IPv6)的归属地,返回与本项目其他查询同一套多源聚合结果。
|
||||
|
||||
- IP 写在**路径**里,不是查询串:`/v1/location/106.224.145.147`。IPv6 直接用标准写法(含 `:`)即可,无需 URL 编码以外的特殊处理。
|
||||
- 与「获取客户端公网 IP 及位置」共用同一个处理器与同一份 IP 库,**区别只是"查谁"**:不带路径参数 = 查请求方自己,带 = 查指定地址。
|
||||
- 出参结构与「获取客户端公网 IP 及位置」**完全一致**,见该页的字段表,此处不重复。
|
||||
- 免鉴权规则同所有 `/v1/*` 端点:节点配了 `access-token` 才需要 `Authorization: Bearer`。
|
||||
- 查 IP 归属地**不需要**目标是本项目节点、也不做连通性探测,只查库;因此查任何公网 IP 都是同样耗时。
|
||||
|
||||
### 1.1 公开实例
|
||||
|
||||
本项目对外开放了一个江苏节点,可以直接用它把本接口调通,**无需令牌**:
|
||||
|
||||
| 方式 | 地址 |
|
||||
| --- | --- |
|
||||
| 直连节点(推荐) | `https://cn-jiangsu.api-ipw.wsmdn.top/v1/location/<ip>` |
|
||||
| 经中间件转发 | `https://middleware-1.api-ipw.wsmdn.top/v1/cn-jiangsu/location/<ip>` |
|
||||
|
||||
两种写法都是「节点 / 接口 / 目标」三段:直连时端点本身就是节点,经中间件时多一段节点标识。
|
||||
中间件入口的 `/v1/` 前缀与 `/middleware/` 前缀等价,用哪个都行。
|
||||
|
||||
> 公共实例是**共享**的,调试与小流量接入没问题,请勿高频轮询、批量抓取,也不要拿它当线上服务的依赖。
|
||||
|
||||
### 1.2 还有别的节点 —— 拨测控制台
|
||||
|
||||
上面的江苏节点只是节点池里的一个。节点池的入口是拨测控制台 <https://boce.wsmdn.top>:
|
||||
登录后进「可用节点」页,能看到**全部已启用节点**的节点标识、归属地、归属池(定位 / 拨测)、
|
||||
协议栈与在线状态,每行都能一键复制调用前缀 —— 把上面那个中间件地址换成控制台给你的入口域名,
|
||||
再接上 `/v1/<节点标识>/` 就是完整前缀,**换节点只动中间那一段标识**。
|
||||
|
||||
比自己搭一套省事的地方:
|
||||
|
||||
- **节点现成** —— 名单里的节点都是已经部署好的,不用自己找机器、装程序、配隧道。
|
||||
- **入口现成** —— 统一走 HTTPS 转发,证书与反向代理不用自己操心。
|
||||
- **一套地址调所有节点** —— 换节点只改标识,接口路径、参数、返回结构都不变。
|
||||
- **池与栈标得很清楚** —— 定位类请求走定位池,拨测类走拨测池,两个池都有的节点两种都能接。
|
||||
- **名单会自己更新** —— 新接入的节点自动出现在列表里,不需要改代码。
|
||||
|
||||
用它调本接口(可直接粘贴执行):
|
||||
|
||||
```bash
|
||||
# 用列表里的江苏节点查一个 IP
|
||||
curl https://middleware-1.api-ipw.wsmdn.top/v1/cn-jiangsu/location/106.224.145.147
|
||||
|
||||
# 换成别的节点:只改中间那一段标识
|
||||
curl https://middleware-1.api-ipw.wsmdn.top/v1/<节点标识>/location/106.224.145.147
|
||||
```
|
||||
|
||||
> 节点有上下线,**离线的节点调用会失败**(返回 `502`)——名单上标了在线状态,挑在线的用。
|
||||
|
||||
## 2. 输入参数
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| `ip`(必选,路径) | String | 要查询的 IP,IPv4 或 IPv6 均可,例如 `/v1/location/106.224.145.147` |
|
||||
|
||||
> 路径中的 IP 不要带方括号。IPv6 形如 `/v1/location/2400:3200::1`。
|
||||
|
||||
## 3. 输出参数
|
||||
|
||||
与「获取客户端公网 IP 及位置」相同:顶层为「源名 → 该源结果」的字典,`ip` 字段回显被查询的地址。取值约定(未加载、出错、空字段、经纬度类型)也一致。
|
||||
|
||||
**非法 IP 是"看起来成功"的**:IP 传错时 HTTP 仍返回 `200`,但每个源会各自报错,形如:
|
||||
|
||||
```json
|
||||
{
|
||||
"ip": "not-an-ip",
|
||||
"ip2region": "error: parse ip not-an-ip: invalid ip address: not-an-ip",
|
||||
"maxmind_city": "error: ParseAddr(\"not-an-ip\"): unable to parse IP",
|
||||
"ip2location": { "country": "Invalid IP address.", "city": "Invalid IP address." },
|
||||
"ip2location_asn": { "asn": "Invalid IP address.", "as": "Invalid IP address." }
|
||||
}
|
||||
```
|
||||
|
||||
所以**判断成功与否要看字段内容,不能只看状态码**:字段是对象才有结论;是 `"error: ..."` 字符串或 `"Invalid IP address."` 就是没查到。建议调用前先自行校验 IP 格式。
|
||||
|
||||
## 4. 示例
|
||||
|
||||
### 4.1 cURL 查询指定 IP 的位置
|
||||
|
||||
```bash
|
||||
curl https://cn-jiangsu.api-ipw.wsmdn.top/v1/location/106.224.145.147
|
||||
|
||||
# IPv6 同样直接拼:curl https://cn-jiangsu.api-ipw.wsmdn.top/v1/location/2400:3200::1
|
||||
|
||||
# 经公共中间件转发(见 1.1):
|
||||
# curl https://middleware-1.api-ipw.wsmdn.top/v1/cn-jiangsu/location/106.224.145.147
|
||||
```
|
||||
|
||||
输出示例(节选,真实响应):
|
||||
|
||||
```json
|
||||
{
|
||||
"ip": "106.224.145.147",
|
||||
"ip2region": { "country": "中国", "administrative_area": "江西省", "city": "南昌市", "isp": "电信" },
|
||||
"ip2location": {
|
||||
"country": "China", "country_code": "CN", "administrative_area": "Jiangxi",
|
||||
"city": "Ji'an", "zipcode": "343000", "timezone": "+08:00",
|
||||
"latitude": "27.11716", "longitude": "114.97927"
|
||||
},
|
||||
"qqwry": { "country": "中国", "country_code": "CN", "administrative_area": "江西", "city": "吉安", "isp": "电信" },
|
||||
"geocn": { "country": "中国", "administrative_area": "江西省", "city": "南昌市", "division_code": "360100", "isp": "电信" },
|
||||
"maxmind_asn": { "asn": "AS4134", "org": "Chinanet" }
|
||||
}
|
||||
```
|
||||
|
||||
> 上面同一 IP 出现了**南昌 / 吉安**两种结论:这就是"多源并列、不做合并"的含义——
|
||||
> 各库口径与更新批次不同,写法也不统一(`江西省` / `Jiangxi`、`南昌市` / `Nanchang`)。
|
||||
> 想要单一结论请自行选源或做交叉投票。
|
||||
|
||||
### 4.2 Python
|
||||
|
||||
```python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import requests
|
||||
|
||||
queryIP = '106.224.145.147'
|
||||
r = requests.get('https://cn-jiangsu.api-ipw.wsmdn.top/v1/location/' + queryIP)
|
||||
data = r.json()
|
||||
|
||||
qqwry = data.get('qqwry', {})
|
||||
if isinstance(qqwry, dict):
|
||||
print(qqwry.get('country'), qqwry.get('administrative_area'),
|
||||
qqwry.get('city'), qqwry.get('isp'))
|
||||
else:
|
||||
print('该源不可用:', qqwry)
|
||||
```
|
||||
|
||||
### 4.3 Golang
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
queryIP := "106.224.145.147"
|
||||
|
||||
resp, err := http.Get("https://cn-jiangsu.api-ipw.wsmdn.top/v1/location/" + queryIP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
|
||||
var result map[string]json.RawMessage
|
||||
if err := json.Unmarshal(body, &result); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var loc struct {
|
||||
Country string `json:"country"`
|
||||
City string `json:"city"`
|
||||
Isp string `json:"isp"`
|
||||
}
|
||||
if err := json.Unmarshal(result["qqwry"], &loc); err != nil {
|
||||
fmt.Println("该源不可用,原始值:", string(result["qqwry"]))
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("%s %s %s\n", loc.Country, loc.City, loc.Isp)
|
||||
}
|
||||
```
|
||||
|
||||
## 5. 错误码
|
||||
|
||||
| 现象 | 说明 |
|
||||
| --- | --- |
|
||||
| 字段是 `"Invalid IP address."`(`ip2location` 系列) | 路径里的 IP 不合法。该库对非法输入仍返回对象,值里写明原因 |
|
||||
| 字段是 `"error: ... unable to parse IP"` | 同上,其它源对非法输入直接返回错误字符串 |
|
||||
| `404 page not found` | 该节点 `ipdb` 已关闭,`/v1/location/:ip` 未注册 |
|
||||
| `401` | 节点配了 `access-token` 但未携带正确的 `Authorization: Bearer <access-token>` |
|
||||
| 结果与常识不符 | 免费 IP 库本身有偏差;本项目是**多源并列**,可交叉比对,不保证单一源正确 |
|
||||
@@ -0,0 +1,228 @@
|
||||
# [API] 查询域名的 WHOIS 信息
|
||||
|
||||
## 1. 接口描述
|
||||
|
||||
> 该接口用于学习域名基础信息,请在中国法律许可范围内使用.
|
||||
|
||||
接口地址: `https://cn-jiangsu.api-ipw.wsmdn.top/v1/whois/<domain>`(公开实例,见 1.1)
|
||||
|
||||
请求方法:`GET`
|
||||
|
||||
用途:查询域名注册信息——注册局记录 + 注册商数据,结构化返回,同时附带原始文本。
|
||||
|
||||
本项目自有的查询流程(不是简单地把库调用包一层):
|
||||
|
||||
1. **先问 IANA**:用域名后缀查 `whois.iana.org`,拿到该后缀的注册局服务器(不猜、不硬编码后缀表);
|
||||
2. **只查注册局**:关闭 whois 库自带的转介链,避免被不可达的注册商服务器拖到超时;
|
||||
3. **补查注册商**:若注册局响应里给出注册商转介服务器(如 `.com` 的 thick 注册局),**限时**再查一次,把结果追加进 `raw`;这一步失败不影响已到手的注册局数据;
|
||||
4. **解析失败不算请求失败**:查询/解析的错误放进响应体的 `error` 字段,HTTP 状态码仍是 `200`。
|
||||
|
||||
其他特性:
|
||||
|
||||
- **结果缓存 5 分钟**。缓存键是**传入的原始字符串**,未做归一化:`QQ.com` 与 `qq.com` 各占一份。
|
||||
- **IPv4 / IPv6 双栈解析** whois 服务器地址(Happy Eyeballs,v6 延迟 150ms 起步),某一栈不通时另一栈仍可用。
|
||||
- **超时预算是分层的**:库单跳 6s(主路径 IANA + 注册局两跳),注册商转介补查另有 3s 总预算且失败即弃。
|
||||
- **入参不做归一化**:不剥 `www.`、不吃 `host:port`。要查的是"注册的那个域名"本身。
|
||||
- `QQ.COM`、`qq.com` 都可以(大小写不敏感,结果里 `domain` 统一大写);
|
||||
- `www.qq.com` 会去查这个**子域**,注册信息为空——不是接口坏了;
|
||||
- `qq.com:43` 不支持,返回 `whois: no whois server found for domain: qq.com:43`。
|
||||
- 免鉴权规则同所有 `/v1/*` 端点:节点配了 `access-token` 才需要 `Authorization: Bearer`。
|
||||
|
||||
### 1.1 公开实例
|
||||
|
||||
本项目对外开放了一个江苏节点,可以直接用它把本接口调通,**无需令牌**:
|
||||
|
||||
| 方式 | 地址 |
|
||||
| --- | --- |
|
||||
| 直连节点(推荐) | `https://cn-jiangsu.api-ipw.wsmdn.top/v1/whois/<domain>` |
|
||||
| 经中间件转发 | `https://middleware-1.api-ipw.wsmdn.top/v1/cn-jiangsu/whois/<domain>` |
|
||||
|
||||
两种写法都是「节点 / 接口 / 目标」三段:直连时端点本身就是节点,经中间件时多一段节点标识。
|
||||
中间件入口的 `/v1/` 前缀与 `/middleware/` 前缀等价,用哪个都行。
|
||||
|
||||
> 公共实例是**共享**的,调试与小流量接入没问题,请勿高频轮询、批量抓取,也不要拿它当线上服务的依赖。
|
||||
|
||||
### 1.2 还有别的节点 —— 拨测控制台
|
||||
|
||||
上面的江苏节点只是节点池里的一个。节点池的入口是拨测控制台 <https://boce.wsmdn.top>:
|
||||
登录后进「可用节点」页,能看到**全部已启用节点**的节点标识、归属地、归属池(定位 / 拨测)、
|
||||
协议栈与在线状态,每行都能一键复制调用前缀 —— 把上面那个中间件地址换成控制台给你的入口域名,
|
||||
再接上 `/v1/<节点标识>/` 就是完整前缀,**换节点只动中间那一段标识**。
|
||||
|
||||
比自己搭一套省事的地方:
|
||||
|
||||
- **节点现成** —— 名单里的节点都是已经部署好的,不用自己找机器、装程序、配隧道。
|
||||
- **入口现成** —— 统一走 HTTPS 转发,证书与反向代理不用自己操心。
|
||||
- **一套地址调所有节点** —— 换节点只改标识,接口路径、参数、返回结构都不变。
|
||||
- **池与栈标得很清楚** —— 定位类请求走定位池,拨测类走拨测池,两个池都有的节点两种都能接。
|
||||
- **名单会自己更新** —— 新接入的节点自动出现在列表里,不需要改代码。
|
||||
|
||||
用它调本接口(可直接粘贴执行):
|
||||
|
||||
```bash
|
||||
# 用列表里的江苏节点查一个域名
|
||||
curl https://middleware-1.api-ipw.wsmdn.top/v1/cn-jiangsu/whois/qq.com
|
||||
|
||||
# 换成别的节点:只改中间那一段标识
|
||||
curl https://middleware-1.api-ipw.wsmdn.top/v1/<节点标识>/whois/qq.com
|
||||
```
|
||||
|
||||
> 节点有上下线,**离线的节点调用会失败**(返回 `502`)——名单上标了在线状态,挑在线的用。
|
||||
|
||||
## 2. 输入参数
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| `domain`(必选,路径) | String | 要查询的域名,例如 `/v1/whois/qq.com`。写注册域名本身,不要带子域 |
|
||||
|
||||
## 3. 输出参数
|
||||
|
||||
| 参数名称 | 类型 | 描述 |
|
||||
| --- | --- | --- |
|
||||
| `domain` | String | 归一化后的域名(**大写**,如 `QQ.COM`) |
|
||||
| `status` | Array \| null | EPP 状态码列表,如 `["clientTransferProhibited"]`;**没拿到时为 `null`**(不是空数组) |
|
||||
| `registrar.name` | String | 注册商名称 |
|
||||
| `registrar.ianaId` | String | 注册商 IANA ID |
|
||||
| `registrant` | Object | 注册人:`name`/`org`/`phone`/`email`/`province`/`contactUri` |
|
||||
| `technical` | Object | 技术联系人,字段同上 |
|
||||
| `abuseContact` | Object | 滥用投诉联系人,字段同上 |
|
||||
| `dates.registration` | String | 注册时间(RFC3339,缺失为 `""`) |
|
||||
| `dates.expiration` | String | 到期时间(RFC3339,缺失为 `""`) |
|
||||
| `dates.lastChanged` | String | 最后变更时间(RFC3339,缺失为 `""`) |
|
||||
| `nameservers` | Array | NS 列表(保留注册局原始大小写) |
|
||||
| `whoisServer` | String | 最终实际查询的 whois 服务器;未找到后缀对应服务器时为空串 |
|
||||
| `raw` | String | 注册局响应原文(含补查到的注册商内容),排查用 |
|
||||
| `error` | String | 查询/解析错误信息;成功时为空串 `""` |
|
||||
|
||||
判定要点:
|
||||
|
||||
- **字段缺失一律返回空串,不会省略键**;所以判断"有没有数据"要看内容而不是键是否存在。
|
||||
- `status` 为 `null` 与 `[]` 含义不同:前者是**没取到**,后者是取到了但确实没有状态。
|
||||
- 隐私保护(GDPR、注册商隐私服务)会让 `registrant` / `technical` 的字段为空或提示串(例如要求到注册商网页填表才能看邮箱),这是上游数据的样子,不是解析失败。
|
||||
- 想拿"能不能注册 / 什么时候释放",以 `dates.expiration` 与 `status`(是否 `pendingDelete`、`redemptionPeriod`)为准。
|
||||
|
||||
## 4. 示例
|
||||
|
||||
### 4.1 cURL 查询域名注册信息
|
||||
|
||||
```bash
|
||||
curl https://cn-jiangsu.api-ipw.wsmdn.top/v1/whois/qq.com
|
||||
|
||||
# 经公共中间件转发(见 1.1):
|
||||
# curl https://middleware-1.api-ipw.wsmdn.top/v1/cn-jiangsu/whois/qq.com
|
||||
```
|
||||
|
||||
输出示例(真实响应,节选):
|
||||
|
||||
```json
|
||||
{
|
||||
"domain": "QQ.COM",
|
||||
"status": [
|
||||
"clientDeleteProhibited", "clientTransferProhibited", "clientUpdateProhibited",
|
||||
"serverDeleteProhibited", "serverTransferProhibited", "serverUpdateProhibited"
|
||||
],
|
||||
"registrar": { "name": "MarkMonitor Information Technology (Shanghai) Co., Ltd.", "ianaId": "3838" },
|
||||
"registrant": {
|
||||
"name": "",
|
||||
"org": "深圳市腾讯计算机系统有限公司",
|
||||
"phone": "",
|
||||
"email": "select request email form at https://domains.markmonitor.com/whois/qq.com",
|
||||
"province": "",
|
||||
"contactUri": ""
|
||||
},
|
||||
"abuseContact": { "name": "", "org": "", "phone": "+1.2086851750", "email": "abusecomplaints@markmonitor.com" },
|
||||
"dates": {
|
||||
"registration": "1995-05-04T04:00:00Z",
|
||||
"expiration": "2034-07-27T02:09:19Z",
|
||||
"lastChanged": "2026-09-23T10:00:17Z"
|
||||
},
|
||||
"nameservers": ["ns1.qq.com", "ns2.qq.com", "ns3.qq.com", "ns4.qq.com"],
|
||||
"whoisServer": "whois.markmonitor.com",
|
||||
"error": ""
|
||||
}
|
||||
```
|
||||
|
||||
### 4.2 Python
|
||||
|
||||
```python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import requests
|
||||
|
||||
queryDomain = 'qq.com'
|
||||
r = requests.get('https://cn-jiangsu.api-ipw.wsmdn.top/v1/whois/' + queryDomain)
|
||||
data = r.json()
|
||||
|
||||
if data.get('error'):
|
||||
print('查询出错:', data['error'])
|
||||
else:
|
||||
print('Domain Name: %s' % data['domain'])
|
||||
print('Status: %s' % data.get('status'))
|
||||
print('Registrar: %s' % data['registrar']['name'])
|
||||
print('Registration Time: %s' % data['dates']['registration'])
|
||||
print('Expiration Time: %s' % data['dates']['expiration'])
|
||||
```
|
||||
|
||||
### 4.3 Golang
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
queryDomain := "qq.com"
|
||||
|
||||
resp, err := http.Get("https://cn-jiangsu.api-ipw.wsmdn.top/v1/whois/" + queryDomain)
|
||||
if err != nil {
|
||||
fmt.Println("请检查网络")
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
|
||||
var result struct {
|
||||
Domain string `json:"domain"`
|
||||
Status []string `json:"status"`
|
||||
Nameservers []string `json:"nameservers"`
|
||||
Dates struct {
|
||||
Registration string `json:"registration"`
|
||||
Expiration string `json:"expiration"`
|
||||
} `json:"dates"`
|
||||
Registrar struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"registrar"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &result); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if result.Error != "" {
|
||||
fmt.Println("查询出错:", result.Error)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Domain: %s\n", result.Domain)
|
||||
fmt.Printf("Registrar: %s\n", result.Registrar.Name)
|
||||
fmt.Printf("Expiration: %s\n", result.Dates.Expiration)
|
||||
}
|
||||
```
|
||||
|
||||
## 5. 错误码
|
||||
|
||||
| 现象 | 原因与处理 |
|
||||
| --- | --- |
|
||||
| `400 {"error":"Domain parameter is required"}` | 路径里没有域名 |
|
||||
| `401` | 节点配了 `access-token` 而未携带正确的 `Authorization: Bearer <access-token>` |
|
||||
| `500 {"error":"..."}` | 上游查询异常(网络不可达等),可稍后重试 |
|
||||
| `200` 且 `error` 为 `whois: no whois server found for domain: xxx` | 该后缀**没有 whois 服务器**(国家后缀常见)或不支持。换用该后缀的注册局查询入口 |
|
||||
| `200` 且各字段全空、`status` 为 `null` | 域名格式不合法(如 `not_a_domain`),IANA 查不到对应后缀;或传了子域(如 `www.qq.com`),因注册信息不在子域上故为空 |
|
||||
| `200` 但 `registrant`/`technical` 为空或提示串 | 上游做了隐私保护;`raw` 里能看到原文措辞 |
|
||||
| 改了域名的注册信息但查询结果是旧的 | 命中 5 分钟缓存;等待或用另一个节点查(缓存是**节点本地**的) |
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
原版支持 IPv6 本地网络(宽带)开启验证、IPv6 网站开启检测、IPv6 TCPing 延迟测试、IPv6 网站测速、IPv6地址查询、IPv6 DNS解析。
|
||||
镜像站点由于开发者财力限制,测速、TCPing、DNS等需要多地测速节点的功能无重现计划
|
||||
本文档并不一定完全和ipw.cn文档相同,部分文段有删改
|
||||
本文档并不一定完全和原版文档相同,部分文段有删改
|
||||
|
||||
## 本地网络(宽带)开启IPv6验证
|
||||
工具地址:[IPv6 地址查询](https://ipw.wsmdn.top/)。
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
# <span style="background-color: #b95442;color: white;font-size: 0.43em;border-radius: 5px;padding: 2px 5px;">转载</span> JS:检查网络是IPv4还是IPv6
|
||||
|
||||
> 仅供个人测试学习之用,本站不对稳定性负责。
|
||||
|
||||
通过一段 js 代码可以显示用户请求网络是 IPv4 访问优先,还是 IPv6 访问优先。
|
||||
|
||||
## 效果
|
||||
|
||||
> 如果你没有 IPv6 的网络环境,可以先用手机流量访问该页面。
|
||||
|
||||
## 代码
|
||||
|
||||
```html
|
||||
<template>
|
||||
<div>
|
||||
<a href='https://nipw.cn' target='_blank'> <b>访客IP:</b> {{IP}},您的网络 {{IPVersion}} 访问优先</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Axios from "axios";
|
||||
|
||||
export default {
|
||||
name: "Home",
|
||||
data(){
|
||||
return{
|
||||
IP: "",
|
||||
IPVersion: "",
|
||||
}
|
||||
},
|
||||
headers:
|
||||
{
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Access-Control-Allow-Origin': "*"
|
||||
},
|
||||
|
||||
methods:{
|
||||
getData(){
|
||||
var that=this
|
||||
// 双栈接口:按本次请求实际走的协议,返回纯文本的 IPv4 或 IPv6 地址
|
||||
var api = "https://test.wsmdn.top";
|
||||
|
||||
Axios.get(api)
|
||||
.then(function (res) {
|
||||
// handle success
|
||||
console.log(res.data);
|
||||
var ip = String(res.data).trim();
|
||||
console.log(ip);
|
||||
that.IP = ip
|
||||
// 返回的地址含冒号即 IPv6,否则为 IPv4
|
||||
that.IPVersion = ip.indexOf(':') > -1 ? "IPv6" : "IPv4"
|
||||
console.log(that.IPVersion);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error);
|
||||
})
|
||||
.then(function () {
|
||||
// always executed
|
||||
});
|
||||
},
|
||||
},
|
||||
mounted(){
|
||||
this.getData();
|
||||
},
|
||||
}
|
||||
</script>
|
||||
```
|
||||
@@ -35,7 +35,7 @@
|
||||
查看 Response Header 来确认服务器支持的 HTTP 的版本。
|
||||
|
||||
```
|
||||
$ curl -I https://ipw.cn
|
||||
$ curl -I https://nipw.cn
|
||||
HTTP/2 200
|
||||
server: nginx
|
||||
content-type: text/html
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# <span style="background-color: #b95442;color: white;font-size: 0.43em;border-radius: 5px;padding: 2px 5px;">转载</span> 网站如何开启 TLS
|
||||
|
||||
## TLS是什么?
|
||||
|
||||
[RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3](https://datatracker.ietf.org/doc/html/rfc8446)
|
||||
|
||||
TLS allows client/server applications to communicate over the Internet in a way that is designed to prevent eavesdropping, tampering, and message forgery.
|
||||
|
||||
### Major Differences from TLS 1.2
|
||||
|
||||
## Wireshark 抓包分析
|
||||
|
||||
### TCP 三次握手
|
||||
|
||||
- SYN 
|
||||
- SYN ACK 
|
||||
- ACK 
|
||||
|
||||
### TLS 协商
|
||||
|
||||
以 TLS 1.3 为例
|
||||
|
||||
- Client Hello 
|
||||
- Server Hello, Change Cipher Spec, Encrypted Extensions 
|
||||
- Certificate, Certificate Verify, Finished 
|
||||
- Change Cipher Spec, Finished 
|
||||
@@ -12,7 +12,7 @@
|
||||
- 禁用 IPv6 本地网络
|
||||
```sh
|
||||
# 验证是否可以访问 IPv6 网络
|
||||
$ curl 6.ipw.cn
|
||||
$ curl 6.wsmdn.top
|
||||
2408:824c:200::2b8b:336f:cc9c
|
||||
|
||||
# 找到网络设备的名字,这里用的是 Wi-Fi (因为 macbook 用的是无线网络访问,即 Wi-Fi)
|
||||
@@ -25,12 +25,12 @@ Bluetooth PAN
|
||||
$ networksetup -setv6off Wi-Fi
|
||||
|
||||
# 请求 IPv4/IPv6 双栈网络,返回 IPv4 地址,证明 IPv4 访问优先。
|
||||
$ curl test.ipw.cn
|
||||
$ curl test.wsmdn.top
|
||||
159.75.190.197
|
||||
|
||||
# 访问 IPv6 网络失败
|
||||
$ curl 6.ipw.cn
|
||||
curl: (6) Could not resolve host: 6.ipw.cn
|
||||
$ curl 6.wsmdn.top
|
||||
curl: (6) Could not resolve host: 6.wsmdn.top
|
||||
```
|
||||
- 启用 IPv6 本地网络
|
||||
```sh
|
||||
@@ -38,7 +38,7 @@ curl: (6) Could not resolve host: 6.ipw.cn
|
||||
$ networksetup -setv6automatic Wi-Fi
|
||||
|
||||
# 验证本地 IPv6 网络访问是否成功
|
||||
$ curl test.ipw.cn
|
||||
$ curl test.wsmdn.top
|
||||
2408:824c:200::2b8b:336f:cc9c
|
||||
```
|
||||
## Window10 禁用或启用 IPv6 本地网络
|
||||
@@ -55,7 +55,7 @@ WLAN Internet 协议版本 6 (TCP/IPv6)
|
||||
以太网 Internet 协议版本 6 (TCP/IPv6) ms_tcpip6 True
|
||||
|
||||
# 验证本地 IPv6 网络是否访问成功
|
||||
PS C:\WINDOWS\system32> curl 6.ipw.cn
|
||||
PS C:\WINDOWS\system32> curl 6.wsmdn.top
|
||||
Content : 2408:824c:200::2b8b:336f:cc9c
|
||||
|
||||
# 禁用 WLAN 设备的本地 IPv6 网络(因为笔记本用的是 无线,即 WLAN)
|
||||
@@ -70,10 +70,10 @@ WLAN Internet 协议版本 6 (TCP/IPv6)
|
||||
以太网 Internet 协议版本 6 (TCP/IPv6) ms_tcpip6 True
|
||||
|
||||
# 无法访问 IPv6 网络
|
||||
PS C:\WINDOWS\system32> curl 6.ipw.cn
|
||||
PS C:\WINDOWS\system32> curl 6.wsmdn.top
|
||||
curl : 无法连接到远程服务器
|
||||
|
||||
PS C:\WINDOWS\system32> curl 4.ipw.cn
|
||||
PS C:\WINDOWS\system32> curl 4.wsmdn.top
|
||||
Content : 159.75.190.197
|
||||
```
|
||||
- 启用 IPv6 本地网络
|
||||
@@ -82,7 +82,7 @@ Content : 159.75.190.197
|
||||
PS C:\WINDOWS\system32> Enable-NetAdapterBinding -Name "WLAN" -ComponentID ms_tcpip6
|
||||
|
||||
# 验证 IPv6 网络是否访问成功
|
||||
PS C:\WINDOWS\system32> curl 6.ipw.cn
|
||||
PS C:\WINDOWS\system32> curl 6.wsmdn.top
|
||||
|
||||
Content : 2408:824c:200::2b8b:336f:cc9c
|
||||
```
|
||||
@@ -97,15 +97,15 @@ Content : 2408:824c:200::2b8b:336f:cc9c
|
||||
$ networksetup -setv4off Wi-Fi
|
||||
|
||||
# 访问 IPv4 网络失败
|
||||
$ curl 4.ipw.cn
|
||||
curl: (6) Could not resolve host: 4.ipw.cn
|
||||
$ curl 4.wsmdn.top
|
||||
curl: (6) Could not resolve host: 4.wsmdn.top
|
||||
```
|
||||
|
||||
- 启用 IPv4 本地网络
|
||||
```sh
|
||||
$ networksetup -setdhcp Wi-Fi
|
||||
|
||||
$ curl 4.ipw.cn
|
||||
$ curl 4.wsmdn.top
|
||||
159.75.190.197
|
||||
```
|
||||
### Window10 禁用/启用IPv4本地网络
|
||||
@@ -115,13 +115,13 @@ $ curl 4.ipw.cn
|
||||
```sh
|
||||
PS C:\WINDOWS\system32> Disable-NetAdapterBinding -Name "WLAN" -ComponentID ms_tcpip
|
||||
|
||||
PS C:\WINDOWS\system32> curl 4.ipw.cn
|
||||
PS C:\WINDOWS\system32> curl 4.wsmdn.top
|
||||
curl : 无法连接到远程服务器
|
||||
```
|
||||
- 启用 IPv4 本地网络
|
||||
```sh
|
||||
PS C:\WINDOWS\system32> Enable-NetAdapterBinding -Name "WLAN" -ComponentID ms_tcpip
|
||||
|
||||
PS C:\WINDOWS\system32> curl 4.ipw.cn
|
||||
PS C:\WINDOWS\system32> curl 4.wsmdn.top
|
||||
159.75.190.197
|
||||
```
|
||||
@@ -0,0 +1,218 @@
|
||||
# <span style="background-color: #b95442;color: white;font-size: 0.43em;border-radius: 5px;padding: 2px 5px;">转载</span> Python/Golang获取 IPv4 和 IPv6 地址
|
||||
|
||||
> 本站是个人站点,用于作者实战学习前端和后台知识,请勿用于商业用途,仅供个人测试学习之用,请遵守中国法律法规
|
||||
|
||||
通过 Python/Golang 获取公网 IPv4 和 IPv6 地址,还可以返回是 IPv4 还是 IPv6 访问优先。
|
||||
|
||||
## 1. Python/Golang获取 IPv4 地址
|
||||
|
||||
### 1.1 Python 获取本机公网IPv4地址
|
||||
|
||||
- 输入示例
|
||||
|
||||
```python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import requests
|
||||
|
||||
# 获取 IPv4 地址接口; https://4.wsmdn.top
|
||||
r = requests.get('https://4.wsmdn.top')
|
||||
|
||||
clientIP = r.text
|
||||
|
||||
print(clientIP)
|
||||
```
|
||||
|
||||
- 输出示例
|
||||
|
||||
```
|
||||
106.224.145.147
|
||||
```
|
||||
|
||||
### 1.2 Golang 获取本机公网IPv4 地址
|
||||
|
||||
- 输入示例
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// 获取 IPv4 地址接口; https://4.wsmdn.top
|
||||
responseClient, errClient := http.Get("https://4.wsmdn.top")
|
||||
|
||||
if errClient != nil {
|
||||
fmt.Printf("获取外网 IP 失败,请检查网络\n")
|
||||
panic(errClient)
|
||||
}
|
||||
defer responseClient.Body.Close()
|
||||
|
||||
// 获取 http response 的 body
|
||||
body, _ := ioutil.ReadAll(responseClient.Body)
|
||||
clientIP := string(body)
|
||||
|
||||
print(clientIP)
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
- 输出示例
|
||||
|
||||
```
|
||||
106.224.145.147
|
||||
```
|
||||
|
||||
## 2. Python/Golang获取 IPv6 地址
|
||||
|
||||
### 2.1 Python 获取本机公网IPv6地址
|
||||
|
||||
- 输入示例
|
||||
|
||||
```python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import requests
|
||||
|
||||
r = requests.get('https://6.wsmdn.top')
|
||||
|
||||
clientIP = r.text
|
||||
|
||||
print(clientIP)
|
||||
```
|
||||
|
||||
- 输出示例
|
||||
|
||||
```
|
||||
2408:824c:200::2b8b:336f:cc9c
|
||||
```
|
||||
|
||||
### 2.2 Golang 获取本机公网IPv6地址
|
||||
|
||||
- 输入示例
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
responseClient, errClient := http.Get("https://6.wsmdn.top")
|
||||
|
||||
if errClient != nil {
|
||||
fmt.Printf("获取外网 IP 失败,请检查网络\n")
|
||||
panic(errClient)
|
||||
}
|
||||
defer responseClient.Body.Close()
|
||||
|
||||
// 获取 http response 的 body
|
||||
body, _ := ioutil.ReadAll(responseClient.Body)
|
||||
clientIP := string(body)
|
||||
|
||||
print(clientIP)
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
- 输出示例
|
||||
|
||||
```
|
||||
2408:824c:200::2b8b:336f:cc9c
|
||||
```
|
||||
|
||||
## 3. 测试网络是IPv4还是IPv6访问优先
|
||||
|
||||
### 3.1 Python 测试网络是IPv4还是IPv6访问优先
|
||||
|
||||
- 输入示例
|
||||
|
||||
```python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import requests
|
||||
|
||||
## HTTP GET,返回的是纯文本地址
|
||||
r = requests.get('https://test.wsmdn.top')
|
||||
|
||||
IP = r.text.strip()
|
||||
|
||||
## 返回的地址含冒号即 IPv6,否则为 IPv4
|
||||
IPVersion = 'IPv6' if ':' in IP else 'IPv4'
|
||||
|
||||
## 打印
|
||||
print('IP:',IP)
|
||||
print('IPVersion:',IPVersion)
|
||||
```
|
||||
|
||||
- 输出示例
|
||||
|
||||
```bash
|
||||
## 返回示例1(IPv4 访问优先)
|
||||
IP: 106.224.145.147
|
||||
IPVersion: IPv4
|
||||
|
||||
## 返回示例2(IPv6 访问优先)
|
||||
IP: 2408:824c:200::2b8b:336f:cc9c
|
||||
IPVersion: IPv6
|
||||
```
|
||||
|
||||
### 3.2 Golang 测试网络是IPv4还是IPv6访问优先
|
||||
|
||||
- 输入示例
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
responseClient, errClient := http.Get("https://test.wsmdn.top") // 获取外网 IP
|
||||
if errClient != nil {
|
||||
fmt.Printf("获取外网 IP 失败,请检查网络\n")
|
||||
panic(errClient)
|
||||
}
|
||||
// 程序在使用完 response 后必须关闭 response 的主体。
|
||||
defer responseClient.Body.Close()
|
||||
|
||||
body, _ := ioutil.ReadAll(responseClient.Body)
|
||||
|
||||
IP := strings.TrimSpace(string(body))
|
||||
|
||||
// 返回的地址含冒号即 IPv6,否则为 IPv4
|
||||
IPVersion := "IPv4"
|
||||
if strings.Contains(IP, ":") {
|
||||
IPVersion = "IPv6"
|
||||
}
|
||||
|
||||
fmt.Printf("IP: %s\n", IP)
|
||||
fmt.Printf("IPVersion: %s\n", IPVersion)
|
||||
}
|
||||
```
|
||||
|
||||
- 输出示例
|
||||
|
||||
```bash
|
||||
## 返回示例1(IPv4 访问优先)
|
||||
IP: 106.224.145.147
|
||||
IPVersion: IPv4
|
||||
|
||||
## 返回示例2(IPv6 访问优先)
|
||||
IP: 2408:824c:200::2b8b:336f:cc9c
|
||||
IPVersion: IPv6
|
||||
```
|
||||
@@ -0,0 +1,25 @@
|
||||
# <span style="background-color: #b95442;color: white;font-size: 0.43em;border-radius: 5px;padding: 2px 5px;">转载</span> DNS解析流程
|
||||
|
||||
## SRV 记录
|
||||
|
||||
SRV 记录:找到要添加 SRV 记录的位置,然后输入:
|
||||
|
||||
端口 协议 名称 服务 优先级 权重 目标 443 _tcp @ _autodiscover 100 1 autodiscover.secureserver.net
|
||||
|
||||

|
||||
|
||||
### 用途
|
||||
|
||||
SRV记录,全称为服务定位(Service Location)记录,是一种在DNS(域名系统)中指定服务位置的记录。它允许用户不仅可以通过域名找到一个服务的地址,还可以找到该服务在特定主机上运行的端口号以及该服务的一些额外信息。SRV记录在多种网络服务中起着关键作用,尤其是在需要定位特定类型服务的应用场景中,如电子邮件、即时通讯、VoIP(Voice over Internet Protocol)等。
|
||||
|
||||
根据您提供的信息,我们可以详细解读这条SRV记录的各个组成部分及其用途:
|
||||
|
||||
- **端口(Port):**`443`。这是服务监听的端口号。在这个例子中,端口443通常用于HTTPS服务,表示这是一个通过安全的方式提供服务的端口。
|
||||
- **协议(Protocol):**`_tcp`。这指定了服务使用的协议类型。在这里,`_tcp`表示该服务使用TCP(传输控制协议)进行通信。SRV记录中的协议通常以`_`开头。
|
||||
- **名称(Name):**`@`。这通常表示当前域,即将这条SRV记录应用于整个域。有时,这里可以指定子域或特定主机。
|
||||
- **服务(Service):**`_autodiscover`。这指定了服务的类型。在这个例子中,`_autodiscover`服务通常与电子邮件相关,用于自动发现邮件服务器的配置信息,使得用户能够仅通过电子邮件地址和密码自动配置他们的邮件客户端。
|
||||
- **优先级(Priority):**`100`。这个数字表示了多个SRV记录之间的优先级。数字越小,优先级越高。在有多个记录指向不同服务器的情况下,客户端会首先尝试优先级最高的服务器。
|
||||
- **权重(Weight):**`1`。当有多个具有相同优先级的SRV记录时,权重决定了这些记录的相对处理顺序。权重越高,该服务器被选中的可能性就越大。权重用于在具有相同优先级的服务器之间分配负载。
|
||||
- **目标(Target):**`autodiscover.secureserver.net`。这是提供服务的服务器的域名。客户端将使用这个地址来访问服务。
|
||||
|
||||
总的来说,这条SRV记录的用途是指导客户端如何找到并连接到提供`_autodiscover`服务的服务器。这对于自动配置电子邮件客户端尤其重要,因为它简化了用户设置邮箱的过程,使用户无需手动输入服务器地址和端口信息。
|
||||
@@ -86,13 +86,13 @@ IPv6 网络开启成功后,我们需要验证下是否真正开启成功。
|
||||
>该站点仅支持 IPv6 网络访问,IPv4 网络无法访问。
|
||||
|
||||
```json
|
||||
// https://6.ipw.cn/
|
||||
// https://6.wsmdn.dpdns.org/
|
||||
240e:3b7:3b7:3b7::3b7
|
||||
```
|
||||
打开 [https://test.wsmdn.dpdns.org/](https://test.wsmdn.dpdns.org/),**如果返回的 IPVersion 字段为 IPv6,则当前网络 IPv6 访问优先,**如果返回的 IPVersion 字段为 IPv4,则当前网络 IPv4 访问优先。
|
||||
打开 [https://test.wsmdn.dpdns.org/](https://test.wsmdn.dpdns.org/),**如果返回的是 IPv6 地址,则当前网络 IPv6 访问优先,**如果返回的是 IPv4 地址,则当前网络 IPv4 访问优先。
|
||||
>[test.wsmdn.dpdns.org](https://test.wsmdn.dpdns.org/) 支持 IPv4/IPv6双栈访问。
|
||||
```json
|
||||
// https://test.ipw.cn/
|
||||
// https://test.wsmdn.dpdns.org/
|
||||
240e:3b7:3b7:3b7::3b7
|
||||
```
|
||||
|
||||
@@ -197,7 +197,7 @@ PING6(56=40+8+8 bytes) --> 2402:4e00:40:40::2:331
|
||||
16 bytes from 2402:4e00:40:40::2:331, icmp_seq=1 hlim=53 time=16.393 ms
|
||||
16 bytes from 2402:4e00:40:40::2:331, icmp_seq=2 hlim=53 time=14.736 ms
|
||||
16 bytes from 2402:4e00:40:40::2:331, icmp_seq=3 hlim=53 time=14.062 ms
|
||||
--- ipw.cn ping6 statistics ---
|
||||
--- ipw.wsmdn.top ping6 statistics ---
|
||||
4 packets transmitted, 4 packets received, 0.0% packet loss
|
||||
round-trip min/avg/max/std-dev = 14.062/15.811/18.052/1.547 ms
|
||||
```
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
访问 `http://[2402:4e00:1013:e500:0:9671:f018:4947]` ,会返回本机 IPv6 IP地址。
|
||||
|
||||

|
||||

|
||||
|
||||
如果有端口,在 IP 地址后面添加端口,比如
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
# <span style="background-color: #b95442;color: white;font-size: 0.43em;border-radius: 5px;padding: 2px 5px;">转载</span> Wireshare 分析 IPv6 包
|
||||
|
||||
>[WARNING]
|
||||
>本文的部分URL已失效,但为了保留原文,未作修改
|
||||
|
||||
## 场景
|
||||
|
||||
执行 `curl 6.ipw.cn`,查看本机的 IPv6 通信包。
|
||||
执行 `curl 6.wsmdn.top`,查看本机的 IPv6 通信包。
|
||||
|
||||
> 如果有 DNS 缓存,可以执行 `sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache` 清理缓存
|
||||
|
||||
|
||||
@@ -137,6 +137,9 @@ export default defineEventHandler(async (event) => {
|
||||
method: 'GET',
|
||||
headers: authHeaders,
|
||||
timeout: 15_000,
|
||||
// 关闭 ofetch 内置重试:上游超时/5xx 时它会在同一节点立即重打一遍(retryDelay 默认 0,无退避),
|
||||
// 把 15s 超时变成 30s。重试统一由前端候选循环承担。
|
||||
retry: false,
|
||||
}).catch((error: any) => {
|
||||
console.error(`Error fetching from ${apiBaseUrl}:`, error)
|
||||
const errStatus = error?.status ?? error?.statusCode
|
||||
@@ -179,6 +182,7 @@ export default defineEventHandler(async (event) => {
|
||||
method: 'GET',
|
||||
headers: authHeaders,
|
||||
timeout: 30_000, // tcping/测速上游本身较慢,给更长超时
|
||||
retry: false, // 同上:不让 ofetch 把 30s 超时放大成 60s
|
||||
}).catch((error: any) => {
|
||||
console.error(`Error fetching from ${apiBaseUrl}:`, error)
|
||||
const errStatus = error?.status ?? error?.statusCode
|
||||
|
||||
@@ -31,11 +31,19 @@ function isConnectionError(e: any): boolean {
|
||||
// 401 未授权、403 被 CDN/WAF 风控拦截、418 被反爬/限流标记、502 中间件/上游不可用 —— 换一个节点往往就能恢复
|
||||
const RETRY_STATUS_CODES = new Set([401, 403, 418, 502])
|
||||
|
||||
// 过滤掉 useFetch 专属选项(对 $fetch 无意义),其余(method/query/params/headers/body/timeout 等)原样透传
|
||||
// 过滤掉 useFetch 专属选项(对 $fetch 无意义),其余(method/query/params/headers/body/timeout 等)原样透传。
|
||||
//
|
||||
// 默认关闭 ofetch 内置重试(retry: false):
|
||||
// ofetch 对 GET 默认重试 1 次,且「拿不到响应(网络层错误)」会按 500 参与重试(见 ofetch onError:
|
||||
// responseCode = response.status || 500)。于是 502、429、超时、"连不上"这几种最贵的失败,
|
||||
// 都会在**同一个节点**上被立即重打一遍(retryDelay 默认 0,无退避),
|
||||
// 请求数与等待时间同时 ×2 —— 而外层候选循环本来就会换节点重试,这层纯属重复。
|
||||
// 调用方若显式传 retry,以调用方为准(rest 在后覆盖)。
|
||||
const DEFAULT_RETRY = false
|
||||
|
||||
function toFetchOptions(options?: any) {
|
||||
if (!options) return undefined
|
||||
const { immediate, watch, key, deep, server, lazy, default: _default, transform, pick, getCachedData, dedupe, ...rest } = options
|
||||
return rest
|
||||
const { immediate, watch, key, deep, server, lazy, default: _default, transform, pick, getCachedData, dedupe, ...rest } = options || {}
|
||||
return { retry: DEFAULT_RETRY, ...rest }
|
||||
}
|
||||
|
||||
// useMiddlewareFetch:在 Vue 页面中调用中间件(替代直接 useFetch('/middleware/...'))。
|
||||
@@ -44,6 +52,7 @@ function toFetchOptions(options?: any) {
|
||||
// Nuxt useAsyncData 在 key 变化时会重新绑定 data/error 状态,导致切换后的数据无法可靠渲染):
|
||||
// - 依次尝试 config.Middleware 中的外部节点 + 前端自带中间件兜底;
|
||||
// - 仅当"节点无法连接"或上游返回 401/403/418 时切下一个候选;
|
||||
// - 每次 $fetch 默认 retry: false,同一条通道不会被重打第二遍(重试统一由本循环承担);
|
||||
// - 成功后 data 立即更新为最终节点的数据,调用方 await execute() 后可直接读取并渲染;
|
||||
// - 全部候选失败时 error 为最终错误。
|
||||
export function useMiddlewareFetch<T = any>(url: MaybeRefOrGetter<string>, options?: any) {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package webtest
|
||||
|
||||
// EO(EdgeOne)特供版的 DNS 模块:与主线 ipw-cn/src/webtest/dns.go 同源,
|
||||
// 但保留 EO 部署形态的两点差异:
|
||||
// 1. DoH / UDP 双通道互备(单地址配置下主通道失败自动回退另一通道);
|
||||
// 2. 查询耗时沿调用链透出(float64 毫秒),ResolveIP 供 tcping / speed 复用。
|
||||
// 主线对 dns.go 的行为修正(Rcode 透出、服务器地址格式校验)已同步至此。
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
@@ -7,6 +13,8 @@ import (
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -29,11 +37,20 @@ var dnsServers []string
|
||||
// dnssecServers DNSSEC 专用服务器列表(未配置时沿用 dnsServers)
|
||||
var dnssecServers []string
|
||||
|
||||
// defaultUDPServer 兜底 UDP 服务器
|
||||
const defaultUDPServer = "119.28.28.28:53"
|
||||
|
||||
// DNSResult 统一的 DNS 查询结果格式。
|
||||
//
|
||||
// Rcode / RcodeText 与主线及各节点保持一致:解析器明确应答 NXDOMAIN 时,属于「域名不存在」
|
||||
// 这个业务结论,而不是节点故障 —— 前端据此区分两者,别把负响应误显示成拨测失败。
|
||||
type DNSResult struct {
|
||||
Domain string `json:"domain"`
|
||||
Duration float64 `json:"duration"`
|
||||
Record []string `json:"record"`
|
||||
TTL uint32 `json:"ttl"`
|
||||
Domain string `json:"domain"`
|
||||
Duration float64 `json:"duration"`
|
||||
Record []string `json:"record"`
|
||||
TTL uint32 `json:"ttl"`
|
||||
Rcode int `json:"rcode"` // 解析器应答的 Rcode(0=Success, 3=NXDOMAIN)
|
||||
RcodeText string `json:"rcode_text"` // Rcode 可读名称,如 NXDOMAIN / SERVFAIL
|
||||
}
|
||||
|
||||
// SetDNSServer 设置 DNS 服务器:支持逗号分隔多地址主从 failover(第一个为主,主失败自动切换后续从服务器)。
|
||||
@@ -42,15 +59,22 @@ func SetDNSServer(server string) {
|
||||
if server == "" {
|
||||
return
|
||||
}
|
||||
list := splitServers(server)
|
||||
// dns-server 既能由本地管理面 PATCH 改,也能由远端托管配置下发 —— 都是外部可控输入。
|
||||
// 在这里先挡掉畸形值,总比留到查询时才以"莫名其妙的超时/报错"暴露好排查;
|
||||
// 全部非法时保留原有配置(与"空串不覆盖"的既有语义一致)。
|
||||
list := validServers(splitServers(server))
|
||||
if len(list) == 0 {
|
||||
slog.Warn("all DNS server addresses invalid, keeping previous config", "server", server)
|
||||
return
|
||||
}
|
||||
dnsServers = list
|
||||
// 兼容单地址的旧语义:URL → DoH 主通道;ip:port → UDP 主通道
|
||||
if len(list) == 1 {
|
||||
if strings.HasPrefix(server, "http://") || strings.HasPrefix(server, "https://") {
|
||||
dohEndpoint = server
|
||||
if strings.HasPrefix(list[0], "http://") || strings.HasPrefix(list[0], "https://") {
|
||||
dohEndpoint = list[0]
|
||||
dnsMode = "doh"
|
||||
} else {
|
||||
dnsServer = server
|
||||
dnsServer = list[0]
|
||||
dnsMode = "udp"
|
||||
}
|
||||
}
|
||||
@@ -58,7 +82,7 @@ func SetDNSServer(server string) {
|
||||
|
||||
// SetDNSSecServer 设置 DNSSEC 专用 DNS 服务器(逗号分隔主从;留空 = 沿用 dns-server 配置)
|
||||
func SetDNSSecServer(server string) {
|
||||
if list := splitServers(server); len(list) > 0 {
|
||||
if list := validServers(splitServers(server)); len(list) > 0 {
|
||||
dnssecServers = list
|
||||
}
|
||||
}
|
||||
@@ -75,6 +99,50 @@ func splitServers(s string) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// validServers 过滤掉格式非法的地址(保留原顺序)。
|
||||
// 全部非法时返回空列表,调用方据此保留原有配置。
|
||||
func validServers(list []string) []string {
|
||||
out := make([]string, 0, len(list))
|
||||
for _, s := range list {
|
||||
if err := validateServerAddr(s); err != nil {
|
||||
slog.Warn("ignored invalid DNS server address", "server", s, "error", err)
|
||||
continue
|
||||
}
|
||||
out = append(out, s)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// validateServerAddr 校验单个 DNS 服务器地址的格式:
|
||||
// - DoH URL:必须是 http/https 且 host 非空(**不限制私网** —— 节点自建内网 DoH 是合理部署);
|
||||
// - UDP/TCP:必须是 host:port 且端口合法。
|
||||
//
|
||||
// 注意:UDP 形式**不禁止私有地址** —— 节点上跑本地缓存解析器(127.0.0.1:53、内网 10.x:53)是常见部署,
|
||||
// 它是节点侧基础设施配置、不是被拨测目标,一并堵掉会直接让 DNS 拨测失效。
|
||||
func validateServerAddr(server string) error {
|
||||
if strings.HasPrefix(server, "http://") || strings.HasPrefix(server, "https://") {
|
||||
u, err := url.Parse(server)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if u.Hostname() == "" {
|
||||
return fmt.Errorf("missing host")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
host, port, err := net.SplitHostPort(server)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.TrimSpace(host) == "" {
|
||||
return fmt.Errorf("missing host")
|
||||
}
|
||||
if p, err := strconv.Atoi(port); err != nil || p < 1 || p > 65535 {
|
||||
return fmt.Errorf("invalid port %q", port)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// ⭐️ 底层核心:DoH + UDP 双通道 DNS 查询
|
||||
// ==========================================
|
||||
@@ -139,9 +207,6 @@ func queryWithServers(msg *dns.Msg, servers []string) (*dns.Msg, float64, error)
|
||||
return nil, 0, lastErr
|
||||
}
|
||||
|
||||
// defaultUDPServer 兜底 UDP 服务器
|
||||
const defaultUDPServer = "119.28.28.28:53"
|
||||
|
||||
// queryUDPMsg 通过 UDP/TCP 向指定 DNS 服务器发送查询(miekg/dns 自动处理大响应切 TCP)
|
||||
func queryUDPMsg(msg *dns.Msg, server string) (*dns.Msg, float64, error) {
|
||||
client := &dns.Client{Timeout: 5 * time.Second}
|
||||
@@ -154,7 +219,12 @@ func queryUDPMsg(msg *dns.Msg, server string) (*dns.Msg, float64, error) {
|
||||
return resp, duration, nil
|
||||
}
|
||||
|
||||
// queryDoHMsg 通过 DoH(RFC 8484,POST application/dns-message)向指定端点发送查询
|
||||
// queryDoHMsg 通过 DoH(RFC 8484,POST application/dns-message)向指定端点发送查询。
|
||||
//
|
||||
// 这里**刻意不做私网/回环拦截**(与 website / ssl / speed 那三处不同):
|
||||
// endpoint 来自 dns-server 配置,而节点上自建内网 DoH(127.0.0.1 / 10.x)是合理部署,
|
||||
// 堵私网会直接打死功能;配置又是管理员凭据才能改的,不构成匿名可达攻击面。
|
||||
// 地址**格式**校验已在 SetDNSServer 入口由 validateServerAddr 完成(http/https + host 非空)。
|
||||
func queryDoHMsg(msg *dns.Msg, endpoint string) (*dns.Msg, float64, error) {
|
||||
packedMsg, err := msg.Pack()
|
||||
if err != nil {
|
||||
@@ -192,209 +262,136 @@ func queryDoHMsg(msg *dns.Msg, endpoint string) (*dns.Msg, float64, error) {
|
||||
// 业务层:构造查询并经双通道执行,提取特定记录
|
||||
// ==========================================
|
||||
|
||||
// executeDoHQuery 构造标准 DNS 请求报文并经双通道执行。
|
||||
//
|
||||
// **不再把 Rcode 非 Success 当错误**:解析器明确应答(哪怕 NXDOMAIN / SERVFAIL)说明网络与
|
||||
// 解析链路是通的,属合法业务结果,由上层透出 Rcode;只有传输/网络层失败才返回 error。
|
||||
// 若在此处返回 error,上层 dnsQueryHandler 会回 500,前端把「域名不存在」显示成「节点故障」。
|
||||
func executeDoHQuery(domain string, qtype uint16) (*dns.Msg, float64, error) {
|
||||
// 1. 构造标准的 DNS 请求报文
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), qtype)
|
||||
msg.RecursionDesired = true // 请求递归解析
|
||||
|
||||
// 2. 双通道查询(DoH 主 + UDP 备,或反之)
|
||||
responseMsg, duration, err := queryDNSMsg(msg)
|
||||
if err != nil {
|
||||
return nil, duration, err
|
||||
}
|
||||
|
||||
// 3. 检查 DNS 响应码 (Rcode)
|
||||
if responseMsg.Rcode != dns.RcodeSuccess {
|
||||
return responseMsg, duration, fmt.Errorf("DNS query failed with Rcode %d", responseMsg.Rcode)
|
||||
}
|
||||
|
||||
return responseMsg, duration, nil
|
||||
return queryDNSMsg(msg)
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 业务层:调用底层函数并提取特定记录
|
||||
// ==========================================
|
||||
|
||||
func ResolveARecord(domain string) (DNSResult, error) {
|
||||
// resolveTyped 通用记录查询:成功收到解析器应答(即便 Rcode 非 Success,如 NXDOMAIN/SERVFAIL)
|
||||
// 即视为一次有效查询,将 Rcode 透出并返回 200;仅在传输/网络层失败(超时、服务器不可达、
|
||||
// DoH 异常)时才返回 error(上层据此返回 500)。避免把合法的负响应误判为节点故障。
|
||||
// extract 从一个 RR 中抽取记录字符串(TXT 可能含多条),返回 (values, ttl, matched)。
|
||||
func resolveTyped(domain, name string, qtype uint16, extract func(dns.RR) ([]string, uint32, bool)) (DNSResult, error) {
|
||||
result := DNSResult{Domain: domain, Record: []string{}}
|
||||
responseMsg, duration, err := executeDoHQuery(domain, dns.TypeA)
|
||||
response, duration, err := executeDoHQuery(name, qtype)
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query A", "domain", domain, "err", err)
|
||||
slog.Warn("Failed to query DNS", "domain", domain, "qtype", qtype, "error", err)
|
||||
return result, err
|
||||
}
|
||||
for _, ans := range responseMsg.Answer {
|
||||
if aRecord, ok := ans.(*dns.A); ok {
|
||||
result.Record = append(result.Record, aRecord.A.String())
|
||||
|
||||
// 解析器已应答:无论 Rcode 是否为 Success,都属合法结果,不再当 error 返回
|
||||
result.Rcode = response.Rcode
|
||||
result.RcodeText = dns.RcodeToString[response.Rcode]
|
||||
for _, ans := range response.Answer {
|
||||
if values, ttl, ok := extract(ans); ok {
|
||||
result.Record = append(result.Record, values...)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = aRecord.Header().Ttl
|
||||
result.TTL = ttl
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func ResolveARecord(domain string) (DNSResult, error) {
|
||||
return resolveTyped(domain, domain, dns.TypeA, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if a, ok := rr.(*dns.A); ok {
|
||||
return []string{a.A.String()}, a.Header().Ttl, true
|
||||
}
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveAAAARecord(domain string) (DNSResult, error) {
|
||||
result := DNSResult{Domain: domain, Record: []string{}}
|
||||
responseMsg, duration, err := executeDoHQuery(domain, dns.TypeAAAA)
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query AAAA", "domain", domain, "err", err)
|
||||
return result, err
|
||||
}
|
||||
for _, ans := range responseMsg.Answer {
|
||||
if aRecord, ok := ans.(*dns.AAAA); ok {
|
||||
result.Record = append(result.Record, aRecord.AAAA.String())
|
||||
if result.TTL == 0 {
|
||||
result.TTL = aRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeAAAA, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if a, ok := rr.(*dns.AAAA); ok {
|
||||
return []string{a.AAAA.String()}, a.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveTXTRecord(domain string) (DNSResult, error) {
|
||||
result := DNSResult{Domain: domain, Record: []string{}}
|
||||
responseMsg, duration, err := executeDoHQuery(domain, dns.TypeTXT)
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query TXT", "domain", domain, "err", err)
|
||||
return result, err
|
||||
}
|
||||
for _, ans := range responseMsg.Answer {
|
||||
if txtRecord, ok := ans.(*dns.TXT); ok {
|
||||
result.Record = append(result.Record, txtRecord.Txt...)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = txtRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeTXT, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if txt, ok := rr.(*dns.TXT); ok {
|
||||
// TXT 一条 RR 可能含多段字符串,保持原有「逐段单独成项」的行为
|
||||
return txt.Txt, txt.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveNSRecord(domain string) (DNSResult, error) {
|
||||
result := DNSResult{Domain: domain, Record: []string{}}
|
||||
responseMsg, duration, err := executeDoHQuery(domain, dns.TypeNS)
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query NS", "domain", domain, "err", err)
|
||||
return result, err
|
||||
}
|
||||
for _, ans := range responseMsg.Answer {
|
||||
if nsRecord, ok := ans.(*dns.NS); ok {
|
||||
result.Record = append(result.Record, nsRecord.Ns)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = nsRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeNS, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if ns, ok := rr.(*dns.NS); ok {
|
||||
return []string{ns.Ns}, ns.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveCNAMERecord(domain string) (DNSResult, error) {
|
||||
result := DNSResult{Domain: domain, Record: []string{}}
|
||||
responseMsg, duration, err := executeDoHQuery(domain, dns.TypeCNAME)
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query CNAME", "domain", domain, "err", err)
|
||||
return result, err
|
||||
}
|
||||
for _, ans := range responseMsg.Answer {
|
||||
if cnameRecord, ok := ans.(*dns.CNAME); ok {
|
||||
result.Record = append(result.Record, cnameRecord.Target)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = cnameRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeCNAME, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if cname, ok := rr.(*dns.CNAME); ok {
|
||||
return []string{cname.Target}, cname.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveMXRecord(domain string) (DNSResult, error) {
|
||||
result := DNSResult{Domain: domain, Record: []string{}}
|
||||
responseMsg, duration, err := executeDoHQuery(domain, dns.TypeMX)
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query MX", "domain", domain, "err", err)
|
||||
return result, err
|
||||
}
|
||||
for _, ans := range responseMsg.Answer {
|
||||
if mxRecord, ok := ans.(*dns.MX); ok {
|
||||
result.Record = append(result.Record, mxRecord.Mx)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = mxRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeMX, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if mx, ok := rr.(*dns.MX); ok {
|
||||
return []string{mx.Mx}, mx.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveSRVRecord(domain string) (DNSResult, error) {
|
||||
result := DNSResult{Domain: domain, Record: []string{}}
|
||||
responseMsg, duration, err := executeDoHQuery(domain, dns.TypeSRV)
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query SRV", "domain", domain, "err", err)
|
||||
return result, err
|
||||
}
|
||||
for _, ans := range responseMsg.Answer {
|
||||
if srvRecord, ok := ans.(*dns.SRV); ok {
|
||||
result.Record = append(result.Record, srvRecord.Target)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = srvRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeSRV, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if srv, ok := rr.(*dns.SRV); ok {
|
||||
return []string{srv.Target}, srv.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func ResolvePTRRecord(ip string) (DNSResult, error) {
|
||||
result := DNSResult{Domain: ip, Record: []string{}}
|
||||
ptrName, err := dns.ReverseAddr(ip)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("invalid IP: %v", err)
|
||||
}
|
||||
|
||||
responseMsg, duration, err := executeDoHQuery(ptrName, dns.TypePTR)
|
||||
result.Duration = duration
|
||||
result.Domain = ip // 保持返回的 Domain 为原始 IP
|
||||
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query PTR", "ip", ip, "err", err)
|
||||
return result, err
|
||||
}
|
||||
for _, ans := range responseMsg.Answer {
|
||||
if ptrRecord, ok := ans.(*dns.PTR); ok {
|
||||
result.Record = append(result.Record, ptrRecord.Ptr)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = ptrRecord.Header().Ttl
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveCAARecord(domain string) (DNSResult, error) {
|
||||
result := DNSResult{Domain: domain, Record: []string{}}
|
||||
responseMsg, duration, err := executeDoHQuery(domain, dns.TypeCAA)
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query CAA", "domain", domain, "err", err)
|
||||
return result, err
|
||||
}
|
||||
for _, ans := range responseMsg.Answer {
|
||||
if caaRecord, ok := ans.(*dns.CAA); ok {
|
||||
result.Record = append(result.Record, caaRecord.Value)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = caaRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeCAA, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if caa, ok := rr.(*dns.CAA); ok {
|
||||
return []string{caa.Value}, caa.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
// ResolveIP 通过 DoH 解析域名,返回指定版本(v4/v6)的 IP 地址字符串
|
||||
// ResolvePTRRecord 反查 IP 的 PTR 记录(返回的 Domain 保持为原始 IP,便于前端直接展示)
|
||||
func ResolvePTRRecord(ip string) (DNSResult, error) {
|
||||
ptrName, err := dns.ReverseAddr(ip)
|
||||
if err != nil {
|
||||
slog.Warn("Invalid IP address for PTR query", "ip", ip, "error", err)
|
||||
return DNSResult{Domain: ip, Record: []string{}}, fmt.Errorf("invalid IP address: %v", err)
|
||||
}
|
||||
return resolveTyped(ip, ptrName, dns.TypePTR, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if ptr, ok := rr.(*dns.PTR); ok {
|
||||
return []string{ptr.Ptr}, ptr.Header().Ttl, true
|
||||
}
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
// ResolveIP 通过双通道解析域名,返回指定版本(v4/v6)的 IP 地址字符串。
|
||||
// EO 特供:供 tcping / speed 等需要"先把 host 归一化成 IP"的拨测复用。
|
||||
func ResolveIP(host string, version string) (string, error) {
|
||||
if ip := net.ParseIP(host); ip != nil {
|
||||
if version == "v4" && ip.To4() != nil {
|
||||
|
||||
@@ -957,14 +957,25 @@ func pingHandler(c *gin.Context) {
|
||||
c.JSON(200, rawResult.(*TCPingResult))
|
||||
}
|
||||
|
||||
// healchCheck 健康检查(GET /)。除 status 外回报版本号:中间件对 HTTP 版节点(无 WS 连接)
|
||||
// 正是靠这个接口探活,顺带取版本用于节点状态页展示。
|
||||
// healchCheck 健康检查(GET /)。只回答"进程是否活着",不回报版本与能力
|
||||
// —— 版本号与能力清单走 GET /info(见 nodeInfoHandler)。
|
||||
//
|
||||
// 分开的理由:健康检查是免鉴权的对外端点,被负载均衡、OTA 就绪探测、运维 curl 打,
|
||||
// 混进版本号等于向公网公开"这个节点跑的是哪个版本",也让一个只该回答存活的端点
|
||||
// 承担了与本意无关的职责。
|
||||
func healchCheck(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
||||
}
|
||||
|
||||
// nodeInfoHandler 节点信息(GET /info):节点版本号 + 能力清单。
|
||||
//
|
||||
// 注册在 /v1 组之外,所以与健康检查一样免鉴权,也不计入拨测统计
|
||||
// (收集中心对纯 HTTP 版节点探活后取回,见 ipw-boce nodeHealth.go)。
|
||||
// 用途:节点状态页展示版本;下发 config 等管理指令前判断节点能否理解对应指令。
|
||||
// 能力清单与 WS register 报文同源(见 ws.go nodeCapabilities)。
|
||||
func nodeInfoHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "ok",
|
||||
"version": VERSION,
|
||||
// 能力清单同 register 报文:中间件对纯 HTTP 节点探活时一并取回,
|
||||
// 用于在下发 config 前判断该节点能否理解对应指令(见 ws.go nodeCapabilities)
|
||||
"version": VERSION,
|
||||
"capabilities": nodeCapabilities(),
|
||||
})
|
||||
}
|
||||
@@ -1327,6 +1338,8 @@ func main() {
|
||||
registerOTARoute(r)
|
||||
|
||||
r.GET("/", healchCheck)
|
||||
// 节点信息(版本 + 能力清单):与健康检查分开,免鉴权、不计入统计(见 nodeInfoHandler)
|
||||
r.GET("/info", nodeInfoHandler)
|
||||
|
||||
// 显式持有 http.Server:收到退出信号时先 Shutdown 释放端口,避免 r.Run 的隐式 Server 无法受控关闭
|
||||
httpServer = &http.Server{Handler: r}
|
||||
|
||||
@@ -337,6 +337,15 @@ func otaDownloadOne(url, dst, wantSHA string) error {
|
||||
return fmt.Errorf("sha256 mismatch: got %s", got)
|
||||
}
|
||||
}
|
||||
// 下载文件默认不带执行位(os.Create 跟随 umask,通常 0644),而 preflightBinary
|
||||
// 在 replaceBinary 的 chmod 之前就要试运行它;Linux 下不显式加 +x 会 EACCES(Permission denied)。
|
||||
// 故此处下载落盘后即补执行位,确保 preflight 与最终 replace 都能 exec。
|
||||
if runtime.GOOS != "windows" {
|
||||
if err := os.Chmod(dst, 0o755); err != nil {
|
||||
_ = os.Remove(dst)
|
||||
return fmt.Errorf("chmod downloaded binary: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -23,14 +26,14 @@ var (
|
||||
// SetDNSServer 设置DNS服务器地址(逗号分隔多地址:第一个为主,主失败自动切换后续从服务器)。
|
||||
// 每项支持 "ip:port"(UDP)或 DoH URL http(s)://...
|
||||
func SetDNSServer(server string) {
|
||||
if list := splitServers(server); len(list) > 0 {
|
||||
if list := validServers(splitServers(server)); len(list) > 0 {
|
||||
dnsServers = list
|
||||
}
|
||||
}
|
||||
|
||||
// SetDNSSecServer 设置DNSSEC专用DNS服务器(逗号分隔主从;留空 = 沿用 dns-server 配置)
|
||||
func SetDNSSecServer(server string) {
|
||||
if list := splitServers(server); len(list) > 0 {
|
||||
if list := validServers(splitServers(server)); len(list) > 0 {
|
||||
dnssecServers = list
|
||||
}
|
||||
}
|
||||
@@ -47,6 +50,53 @@ func splitServers(s string) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// validServers 过滤掉格式非法的地址(保留原顺序)。
|
||||
//
|
||||
// dns-server / dnssec-server 既能由本地管理面 PATCH 改,也能由远端托管配置下发 —— 都是外部可控输入。
|
||||
// 在这里先挡掉畸形值,总比留到查询时才以"莫名其妙的超时/报错"暴露好排查。
|
||||
// 全部非法时返回空列表,调用方据此保留原有配置(与"空串不覆盖"的既有语义一致)。
|
||||
func validServers(list []string) []string {
|
||||
out := make([]string, 0, len(list))
|
||||
for _, s := range list {
|
||||
if err := validateServerAddr(s); err != nil {
|
||||
slog.Warn("ignored invalid DNS server address", "server", s, "error", err)
|
||||
continue
|
||||
}
|
||||
out = append(out, s)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// validateServerAddr 校验单个 DNS 服务器地址的格式:
|
||||
// - DoH URL:必须是 http/https 且 host 非空(**不限制私网** —— 节点自建内网 DoH 是合理部署);
|
||||
// - UDP/TCP:必须是 host:port 且端口合法。
|
||||
//
|
||||
// 注意:UDP 形式**不禁止私有地址** —— 节点上跑本地缓存解析器(127.0.0.1:53、内网 10.x:53)是常见部署,
|
||||
// 它是节点侧基础设施配置、不是被拨测目标,一并堵掉会直接让 DNS 拨测失效。
|
||||
func validateServerAddr(server string) error {
|
||||
if strings.HasPrefix(server, "http://") || strings.HasPrefix(server, "https://") {
|
||||
u, err := url.Parse(server)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if u.Hostname() == "" {
|
||||
return fmt.Errorf("missing host")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
host, port, err := net.SplitHostPort(server)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.TrimSpace(host) == "" {
|
||||
return fmt.Errorf("missing host")
|
||||
}
|
||||
if p, err := strconv.Atoi(port); err != nil || p < 1 || p > 65535 {
|
||||
return fmt.Errorf("invalid port %q", port)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
defaultUDPServer = "119.28.28.28:53"
|
||||
defaultDoHEndpoint = "https://doh.pub/dns-query"
|
||||
@@ -104,7 +154,13 @@ func queryUDPMsg(msg *dns.Msg, server string) (*dns.Msg, error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// queryDoHMsg 通过 DoH(RFC 8484,POST application/dns-message)向指定端点发送查询
|
||||
// queryDoHMsg 通过 DoH(RFC 8484,POST application/dns-message)向指定端点发送查询。
|
||||
//
|
||||
// 这里**刻意不做私网/回环拦截**(与 website / ssl / speed 那三处不同):
|
||||
// endpoint 来自 dns-server 配置,而节点上自建内网 DoH(127.0.0.1 / 10.x)是合理部署,
|
||||
// 堵私网会直接打死功能;配置又是管理员凭据才能改的,不构成匿名可达攻击面。
|
||||
// 地址**格式**校验已在 SetDNSServer 入口由 validateServerAddr 完成(http/https + host 非空)。
|
||||
// 对应 CodeQL go/request-forgery(#24)按误报处理。
|
||||
func queryDoHMsg(msg *dns.Msg, endpoint string) (*dns.Msg, error) {
|
||||
packedMsg, err := msg.Pack()
|
||||
if err != nil {
|
||||
@@ -138,333 +194,132 @@ func queryDoHMsg(msg *dns.Msg, endpoint string) (*dns.Msg, error) {
|
||||
|
||||
// DNSResult 统一的DNS查询结果格式
|
||||
type DNSResult struct {
|
||||
Domain string `json:"domain"`
|
||||
Record []string `json:"record"`
|
||||
TTL uint32 `json:"ttl"`
|
||||
Duration float64 `json:"duration"`
|
||||
Domain string `json:"domain"`
|
||||
Record []string `json:"record"`
|
||||
TTL uint32 `json:"ttl"`
|
||||
Duration float64 `json:"duration"`
|
||||
Rcode int `json:"rcode"` // 解析器应答的 Rcode(0=Success, 3=NXDOMAIN)
|
||||
RcodeText string `json:"rcode_text"` // Rcode 可读名称,如 NXDOMAIN / SERVFAIL
|
||||
}
|
||||
|
||||
// resolveTyped 通用记录查询:成功收到解析器应答(即便 Rcode 非 Success,如 NXDOMAIN/SERVFAIL)
|
||||
// 即视为一次有效查询,将 Rcode 透出并返回 200;仅在传输/网络层失败(超时、服务器不可达、
|
||||
// DoH 异常)时才返回 error(上层据此返回 500)。避免把合法的负响应误判为节点故障。
|
||||
// extract 从一个 RR 中抽取记录字符串(TXT 可能含多条),返回 (values, ttl, matched)。
|
||||
func resolveTyped(domain, name string, qtype uint16, extract func(dns.RR) ([]string, uint32, bool)) (DNSResult, error) {
|
||||
start := time.Now()
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(name), qtype)
|
||||
result := DNSResult{Domain: domain}
|
||||
|
||||
response, err := queryDNS(msg)
|
||||
result.Duration = time.Since(start).Seconds() * 1000
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query DNS", "domain", domain, "qtype", qtype, "error", err)
|
||||
result.Record = []string{}
|
||||
return result, err
|
||||
}
|
||||
|
||||
// 解析器已应答:无论 Rcode 是否为 Success,都属合法结果,不再当 error 返回
|
||||
result.Rcode = response.Rcode
|
||||
result.RcodeText = dns.RcodeToString[response.Rcode]
|
||||
result.Record = []string{}
|
||||
for _, ans := range response.Answer {
|
||||
if values, ttl, ok := extract(ans); ok {
|
||||
result.Record = append(result.Record, values...)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = ttl
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func ResolveARecord(domain string) (DNSResult, error) {
|
||||
start := time.Now()
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), dns.TypeA)
|
||||
result := DNSResult{Domain: domain}
|
||||
|
||||
response, err := queryDNS(msg)
|
||||
duration := time.Since(start).Seconds() * 1000
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query DNS", "domain", domain, "error", err)
|
||||
result.Record = []string{}
|
||||
return result, err
|
||||
}
|
||||
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
slog.Warn("DNS query failed with Rcode", "rcode", response.Rcode)
|
||||
return result, fmt.Errorf("DNS query failed with Rcode %d", response.Rcode)
|
||||
}
|
||||
|
||||
for _, ans := range response.Answer {
|
||||
if aRecord, ok := ans.(*dns.A); ok {
|
||||
result.Record = append(result.Record, aRecord.A.String())
|
||||
if result.TTL == 0 {
|
||||
result.TTL = aRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeA, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if a, ok := rr.(*dns.A); ok {
|
||||
return []string{a.A.String()}, a.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
if result.Record == nil {
|
||||
result.Record = []string{}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveAAAARecord(domain string) (DNSResult, error) {
|
||||
start := time.Now()
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), dns.TypeAAAA)
|
||||
|
||||
result := DNSResult{Domain: domain}
|
||||
|
||||
response, err := queryDNS(msg)
|
||||
duration := time.Since(start).Seconds() * 1000
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query DNS", "domain", domain, "error", err)
|
||||
result.Record = []string{}
|
||||
return result, err
|
||||
}
|
||||
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
slog.Warn("DNS query failed with Rcode", "rcode", response.Rcode)
|
||||
return result, fmt.Errorf("DNS query failed with Rcode %d", response.Rcode)
|
||||
}
|
||||
|
||||
for _, ans := range response.Answer {
|
||||
if aRecord, ok := ans.(*dns.AAAA); ok {
|
||||
result.Record = append(result.Record, aRecord.AAAA.String())
|
||||
if result.TTL == 0 {
|
||||
result.TTL = aRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeAAAA, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if a, ok := rr.(*dns.AAAA); ok {
|
||||
return []string{a.AAAA.String()}, a.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
if result.Record == nil {
|
||||
result.Record = []string{}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveTXTRecord(domain string) (DNSResult, error) {
|
||||
start := time.Now()
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), dns.TypeTXT)
|
||||
|
||||
result := DNSResult{Domain: domain}
|
||||
|
||||
response, err := queryDNS(msg)
|
||||
duration := time.Since(start).Seconds() * 1000
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query DNS", "domain", domain, "error", err)
|
||||
result.Record = []string{}
|
||||
return result, err
|
||||
}
|
||||
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
slog.Warn("DNS query failed with Rcode", "rcode", response.Rcode)
|
||||
return result, fmt.Errorf("DNS query failed with Rcode %d", response.Rcode)
|
||||
}
|
||||
|
||||
for _, ans := range response.Answer {
|
||||
if aRecord, ok := ans.(*dns.TXT); ok {
|
||||
for _, txt := range aRecord.Txt {
|
||||
result.Record = append(result.Record, txt)
|
||||
}
|
||||
if result.TTL == 0 {
|
||||
result.TTL = aRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeTXT, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if txt, ok := rr.(*dns.TXT); ok {
|
||||
// TXT 一条 RR 可能含多段字符串,保持原有「逐段单独成项」的行为
|
||||
return txt.Txt, txt.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
if result.Record == nil {
|
||||
result.Record = []string{}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveNSRecord(domain string) (DNSResult, error) {
|
||||
start := time.Now()
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), dns.TypeNS)
|
||||
|
||||
result := DNSResult{Domain: domain}
|
||||
|
||||
response, err := queryDNS(msg)
|
||||
duration := time.Since(start).Seconds() * 1000
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query DNS", "domain", domain, "error", err)
|
||||
result.Record = []string{}
|
||||
return result, err
|
||||
}
|
||||
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
slog.Warn("DNS query failed with Rcode", "rcode", response.Rcode)
|
||||
return result, fmt.Errorf("DNS query failed with Rcode %d", response.Rcode)
|
||||
}
|
||||
|
||||
for _, ans := range response.Answer {
|
||||
if aRecord, ok := ans.(*dns.NS); ok {
|
||||
result.Record = append(result.Record, aRecord.Ns)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = aRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeNS, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if ns, ok := rr.(*dns.NS); ok {
|
||||
return []string{ns.Ns}, ns.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
if result.Record == nil {
|
||||
result.Record = []string{}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveCNAMERecord(domain string) (DNSResult, error) {
|
||||
start := time.Now()
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), dns.TypeCNAME)
|
||||
|
||||
result := DNSResult{Domain: domain}
|
||||
|
||||
response, err := queryDNS(msg)
|
||||
duration := time.Since(start).Seconds() * 1000
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query CNAME", "domain", domain, "error", err)
|
||||
result.Record = []string{}
|
||||
return result, err
|
||||
}
|
||||
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
slog.Warn("CNAME query failed with Rcode", "rcode", response.Rcode)
|
||||
return result, fmt.Errorf("CNAME query failed with Rcode %d", response.Rcode)
|
||||
}
|
||||
|
||||
for _, ans := range response.Answer {
|
||||
if cnameRecord, ok := ans.(*dns.CNAME); ok {
|
||||
result.Record = append(result.Record, cnameRecord.Target)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = cnameRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeCNAME, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if cname, ok := rr.(*dns.CNAME); ok {
|
||||
return []string{cname.Target}, cname.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
if result.Record == nil {
|
||||
result.Record = []string{}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveMXRecord(domain string) (DNSResult, error) {
|
||||
start := time.Now()
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), dns.TypeMX)
|
||||
|
||||
result := DNSResult{Domain: domain}
|
||||
|
||||
response, err := queryDNS(msg)
|
||||
duration := time.Since(start).Seconds() * 1000
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query MX", "domain", domain, "error", err)
|
||||
result.Record = []string{}
|
||||
return result, err
|
||||
}
|
||||
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
slog.Warn("MX query failed with Rcode", "rcode", response.Rcode)
|
||||
return result, fmt.Errorf("MX query failed with Rcode %d", response.Rcode)
|
||||
}
|
||||
|
||||
for _, ans := range response.Answer {
|
||||
if mxRecord, ok := ans.(*dns.MX); ok {
|
||||
result.Record = append(result.Record, mxRecord.Mx)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = mxRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeMX, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if mx, ok := rr.(*dns.MX); ok {
|
||||
return []string{mx.Mx}, mx.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
if result.Record == nil {
|
||||
result.Record = []string{}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveSRVRecord(domain string) (DNSResult, error) {
|
||||
start := time.Now()
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), dns.TypeSRV)
|
||||
|
||||
result := DNSResult{Domain: domain}
|
||||
|
||||
response, err := queryDNS(msg)
|
||||
duration := time.Since(start).Seconds() * 1000
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query SRV", "domain", domain, "error", err)
|
||||
result.Record = []string{}
|
||||
return result, err
|
||||
}
|
||||
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
slog.Warn("SRV query failed with Rcode", "rcode", response.Rcode)
|
||||
return result, fmt.Errorf("SRV query failed with Rcode %d", response.Rcode)
|
||||
}
|
||||
|
||||
for _, ans := range response.Answer {
|
||||
if srvRecord, ok := ans.(*dns.SRV); ok {
|
||||
result.Record = append(result.Record, srvRecord.Target)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = srvRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeSRV, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if srv, ok := rr.(*dns.SRV); ok {
|
||||
return []string{srv.Target}, srv.Header().Ttl, true
|
||||
}
|
||||
}
|
||||
if result.Record == nil {
|
||||
result.Record = []string{}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func ResolvePTRRecord(ip string) (DNSResult, error) {
|
||||
start := time.Now()
|
||||
ptrName, err := dns.ReverseAddr(ip)
|
||||
if err != nil {
|
||||
slog.Warn("Invalid IP address for PTR query", "ip", ip, "error", err)
|
||||
result := DNSResult{Domain: ip, Record: []string{}}
|
||||
return result, fmt.Errorf("invalid IP address: %v", err)
|
||||
}
|
||||
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(ptrName, dns.TypePTR)
|
||||
|
||||
result := DNSResult{Domain: ip}
|
||||
|
||||
response, err := queryDNS(msg)
|
||||
duration := time.Since(start).Seconds() * 1000
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query PTR", "ip", ip, "error", err)
|
||||
result.Record = []string{}
|
||||
return result, err
|
||||
}
|
||||
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
slog.Warn("PTR query failed with Rcode", "rcode", response.Rcode)
|
||||
return result, fmt.Errorf("PTR query failed with Rcode %d", response.Rcode)
|
||||
}
|
||||
|
||||
for _, ans := range response.Answer {
|
||||
if ptrRecord, ok := ans.(*dns.PTR); ok {
|
||||
result.Record = append(result.Record, ptrRecord.Ptr)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = ptrRecord.Header().Ttl
|
||||
}
|
||||
}
|
||||
}
|
||||
if result.Record == nil {
|
||||
result.Record = []string{}
|
||||
}
|
||||
return result, nil
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolveCAARecord(domain string) (DNSResult, error) {
|
||||
start := time.Now()
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), dns.TypeCAA)
|
||||
|
||||
result := DNSResult{Domain: domain}
|
||||
|
||||
response, err := queryDNS(msg)
|
||||
duration := time.Since(start).Seconds() * 1000
|
||||
result.Duration = duration
|
||||
if err != nil {
|
||||
slog.Warn("Failed to query CAA", "domain", domain, "error", err)
|
||||
result.Record = []string{}
|
||||
return result, err
|
||||
}
|
||||
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
slog.Warn("CAA query failed with Rcode", "rcode", response.Rcode)
|
||||
return result, fmt.Errorf("CAA query failed with Rcode %d", response.Rcode)
|
||||
}
|
||||
|
||||
for _, ans := range response.Answer {
|
||||
if caaRecord, ok := ans.(*dns.CAA); ok {
|
||||
result.Record = append(result.Record, caaRecord.Value)
|
||||
if result.TTL == 0 {
|
||||
result.TTL = caaRecord.Header().Ttl
|
||||
}
|
||||
return resolveTyped(domain, domain, dns.TypeCAA, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if caa, ok := rr.(*dns.CAA); ok {
|
||||
return []string{caa.Value}, caa.Header().Ttl, true
|
||||
}
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
func ResolvePTRRecord(ip string) (DNSResult, error) {
|
||||
ptrName, err := dns.ReverseAddr(ip)
|
||||
if err != nil {
|
||||
slog.Warn("Invalid IP address for PTR query", "ip", ip, "error", err)
|
||||
return DNSResult{Domain: ip, Record: []string{}}, fmt.Errorf("invalid IP address: %v", err)
|
||||
}
|
||||
if result.Record == nil {
|
||||
result.Record = []string{}
|
||||
}
|
||||
return result, nil
|
||||
return resolveTyped(ip, ptrName, dns.TypePTR, func(rr dns.RR) ([]string, uint32, bool) {
|
||||
if ptr, ok := rr.(*dns.PTR); ok {
|
||||
return []string{ptr.Ptr}, ptr.Header().Ttl, true
|
||||
}
|
||||
return nil, 0, false
|
||||
})
|
||||
}
|
||||
|
||||
// DNSFullResult 完整的DNS查询结果(不包含PTR,PTR需单独查询)
|
||||
|
||||
@@ -89,20 +89,138 @@ const happyEyeballsV6Delay = 150 * time.Millisecond
|
||||
// whoisConnectTimeout 单 IP 连接 + 读写超时上限
|
||||
const whoisConnectTimeout = 10 * time.Second
|
||||
|
||||
// whoisLibTimeout likexian/whois 单跳超时上限(库的超时按「跳」计,同一跳内读写共享该预算)。
|
||||
// 库默认 30s:一旦注册商转介指向不可达地址(如 Cloudflare 后的网站域名,43 端口被丢弃),
|
||||
// 单跳干等 30s,整条查询必然超过中心拨测默认 30s 超时。
|
||||
// 主路径只剩 IANA + 注册局两跳(转介已改为独立限时补查),2×6s 仍在中心超时之内。
|
||||
const whoisLibTimeout = 6 * time.Second
|
||||
|
||||
// whoisReferralTimeout 自行补查注册商转介的总超时。
|
||||
// 转介只是「锦上添花」,失败即放弃,绝不阻塞已到手的注册局数据。
|
||||
const whoisReferralTimeout = 3 * time.Second
|
||||
|
||||
// QueryWhois 执行 WHOIS 查询并解析结构化数据
|
||||
// 使用 likexian/whois 库查询原始响应,再用 whois-parser 解析为结构化数据
|
||||
// 首次失败后 fallback:内置 TLD 映射 → IANA 查询服务器地址 →
|
||||
// 用 ResolveA/AAAA(自定义DNS) 解析IP → Happy Eyeballs 双栈竞争拨号
|
||||
// 主路径:likexian/whois 走「IANA → 注册局」两跳,**不追注册商转介**(转介由 chaseReferral 单独限时补),
|
||||
// 这样即便转介服务器不可达也只在 ~1s 内拿到注册局记录,不会干等满库的 30s 超时。
|
||||
// 兜底:主路径拿不到内容时才 fallback(内置 TLD 映射 → IANA 查服务器 → 自定义 DNS 解析 IP →
|
||||
// Happy Eyeballs 双栈竞争拨号)。
|
||||
func QueryWhois(domain string) (*WhoisResult, error) {
|
||||
raw, err := whois.Whois(domain)
|
||||
if err != nil {
|
||||
raw, err = whoisRetryWithFallback(domain, err)
|
||||
raw, err := queryWhoisRegistry(domain)
|
||||
|
||||
// 库在「连接成功但读失败」等场景会同时返回部分数据与错误,此时数据不能丢;
|
||||
// 因此只在「内容为空」或「带错误」时让 fallback 再兜一次,并取内容更长的一方。
|
||||
if err != nil || raw == "" {
|
||||
if fb, fbErr := whoisRetryWithFallback(domain, err); len(fb) > len(raw) {
|
||||
raw, err = fb, fbErr
|
||||
}
|
||||
}
|
||||
|
||||
// 仅当注册局响应干净(err == nil)时才补查注册商转介
|
||||
if err == nil && raw != "" {
|
||||
if extra := chaseReferral(domain, raw); extra != "" {
|
||||
raw += extra
|
||||
}
|
||||
}
|
||||
|
||||
result := parseWhoisResult(domain, raw)
|
||||
result.Error = errString(err)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// queryWhoisRegistry 走 IANA → 注册局两跳取注册局记录,关闭库的转介链
|
||||
// (转介改由 chaseReferral 限时补查,避免被不可达的转介服务器拖满 30s)
|
||||
func queryWhoisRegistry(domain string) (string, error) {
|
||||
return whois.NewClient().
|
||||
SetDisableReferral(true).
|
||||
SetTimeout(whoisLibTimeout).
|
||||
Whois(domain)
|
||||
}
|
||||
|
||||
// chaseReferral 从注册局响应里取出注册商转介服务器,限时补查一次
|
||||
// 任何失败(无转介 / 不可达 / 超时)都返回空串,绝不影响已到手的注册局数据
|
||||
func chaseReferral(domain, raw string) string {
|
||||
server, port := extractReferralServer(raw)
|
||||
if server == "" {
|
||||
return ""
|
||||
}
|
||||
// 转介指向的仍是刚查过的注册局服务器(库自带判断的同款保护)
|
||||
if ext := getExtension(domain); strings.EqualFold(tldWhoisServers[ext], server) {
|
||||
return ""
|
||||
}
|
||||
|
||||
v4IPs, v6IPs, err := resolveWhoisServerIPs(server)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), whoisReferralTimeout)
|
||||
defer cancel()
|
||||
|
||||
data, err := happyEyeballsWhoisQuery(ctx, domain, v4IPs, v6IPs, port)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// referralKeys 指向「下一个 WHOIS 服务器」的字段名(小写,按优先级前缀匹配)
|
||||
var referralKeys = []string{"registrar whois server", "referralserver", "whois", "referral"}
|
||||
|
||||
// normalizeReferralValue 规整转介地址:去协议前缀 / 路径 / 认证尾巴,拆出 host 与 port
|
||||
// 返回 "" 表示不是可用的 whois 转介。rwhois 是另一种协议,拨过去同样是白等,直接跳过
|
||||
func normalizeReferralValue(value string) (string, string) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" || strings.HasPrefix(strings.ToLower(value), "rwhois:") {
|
||||
return "", ""
|
||||
}
|
||||
for _, prefix := range []string{"http://", "https://", "whois://"} {
|
||||
value = strings.TrimPrefix(value, prefix)
|
||||
}
|
||||
if i := strings.IndexAny(value, "/,"); i != -1 {
|
||||
value = value[:i]
|
||||
}
|
||||
value = strings.TrimSpace(value)
|
||||
|
||||
host, port := value, "43"
|
||||
if h, p, err := net.SplitHostPort(value); err == nil {
|
||||
host, port = h, p
|
||||
}
|
||||
// 合法性:必须是形如 whois.example.com 的主机名,排除 "Server: xxx" 之类的误匹配
|
||||
if host == "" || strings.ContainsAny(host, " \t:/,") || !strings.Contains(host, ".") {
|
||||
return "", ""
|
||||
}
|
||||
return host, port
|
||||
}
|
||||
|
||||
// extractReferralServer 从注册局响应中解析注册商转介的 WHOIS 服务器与端口,取不到返回 ("", "")
|
||||
// 覆盖两种写法:字段式(Registrar WHOIS Server: / ReferralServer: / whois:)
|
||||
// 与注释式(%referral whois://host:4321/auth-area=.)
|
||||
func extractReferralServer(raw string) (string, string) {
|
||||
for _, line := range strings.Split(raw, "\n") {
|
||||
// 归一化:去掉 % / # 注释前缀
|
||||
line = strings.TrimLeft(strings.TrimSpace(line), "%# \t")
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
lower := strings.ToLower(line)
|
||||
for _, key := range referralKeys {
|
||||
if !strings.HasPrefix(lower, key) {
|
||||
continue
|
||||
}
|
||||
// 从 lower 切分,避免 ToLower 改变长度时错位(主机名大小写不敏感)
|
||||
rest := strings.TrimSpace(lower[len(key):])
|
||||
rest = strings.TrimSpace(strings.TrimPrefix(rest, ":"))
|
||||
if rest == "" {
|
||||
continue
|
||||
}
|
||||
if server, port := normalizeReferralValue(rest); server != "" {
|
||||
return server, port
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// errString safely converts an error to string
|
||||
func errString(err error) string {
|
||||
if err == nil {
|
||||
@@ -187,12 +305,13 @@ func resolveWhoisServerIPs(server string) (v4IPs, v6IPs []string, err error) {
|
||||
// - 等待 happyEyeballsV6Delay 后并发拨号所有 IPv6 IP
|
||||
// - 取第一个成功完成 WHOIS 查询的结果返回
|
||||
// - 其他仍在运行的 goroutine 通过 context 取消尽快退出
|
||||
func happyEyeballsWhoisQuery(domain string, v4IPs, v6IPs []string, port string) (string, error) {
|
||||
// parent 带 deadline 时(追注册商转介),到点即整体放弃
|
||||
func happyEyeballsWhoisQuery(parent context.Context, domain string, v4IPs, v6IPs []string, port string) (string, error) {
|
||||
if len(v4IPs) == 0 && len(v6IPs) == 0 {
|
||||
return "", fmt.Errorf("no IPs available for WHOIS query")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(parent)
|
||||
defer cancel()
|
||||
|
||||
type outcome struct {
|
||||
@@ -269,7 +388,7 @@ func whoisRetryWithFallback(domain string, firstErr error) (string, error) {
|
||||
}
|
||||
|
||||
// Happy Eyeballs 双栈竞争拨号 + 并发多 IP
|
||||
raw, err := happyEyeballsWhoisQuery(domain, v4IPs, v6IPs, "43")
|
||||
raw, err := happyEyeballsWhoisQuery(context.Background(), domain, v4IPs, v6IPs, "43")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ const (
|
||||
)
|
||||
|
||||
// nodeCapabilities 本节点支持的远程管理能力清单,随 register 报文上报给中间件,
|
||||
// 同时也在 HTTP 健康检查 `/` 里返回(供中间件对纯 HTTP 节点探活时一并取回)。
|
||||
// 同时也在 HTTP `GET /info` 里返回(供中间件对纯 HTTP 节点取回,健康检查 `/` 只回存活)。
|
||||
//
|
||||
// 存在的意义:中间件下发 config 指令前先查这份清单,
|
||||
// - 清单里没有该能力 → 立刻给出明确错误(旧版节点会静默忽略这类消息,只能白白等满超时)
|
||||
|
||||