| 276 | "\n• <code>.bgp <IP></code> - 查询指定IP的BGP路由图\n" + |
| 277 | "• <code>.bgp</code> - 回复包含IP的消息自动查询BGP路由图\n" + |
| 278 | "• <code>.bgp dns <IP></code> - 查询指定IP的DNS解析记录\n" + |
| 279 | "• <code>.bgp dns</code> - 回复包含IP的消息查询DNS解析记录"; |
| 280 | |
| 281 | cmdHandlers: Record<string, (msg: Api.Message, trigger?: Api.Message) => Promise<void>> = { |
| 282 | bgp: async (msg, trigger) => { |
| 283 | |
| 284 | const client = await getGlobalClient(); |
| 285 | if (!client) { |
| 286 | await msg.edit({ text: "❌ 客户端未初始化" }); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | if (!client.connected) { |
| 291 | try { |
| 292 | await msg.edit({ text: "🔄 正在连接 Telegram..." }); |
| 293 | await client.connect(); |
| 294 | if (!client.connected) throw new Error("连接失败"); |
| 295 | } catch (err: any) { |
| 296 | await msg.edit({ |
| 297 | text: |
| 298 | `❌ <b>连接失败</b>\n\n${htmlEscape(err.message)}\n\n请检查:\n• 网络连接\n• API 凭据\n• 代理设置`, |
| 299 | parseMode: "html", |
| 300 | }); |
| 301 | return; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | let msgDeleted = false; |
| 306 | |
| 307 | try { |
| 308 | let targetIP: string | null = null; |
| 309 | const rawArgs = msg.message.split(" ").slice(1); |
| 310 | |
| 311 | if (rawArgs[0] === "dns") { |
| 312 | const dnsArgs = rawArgs.slice(1); |
| 313 | targetIP = await resolveTargetIP(dnsArgs, msg, trigger); |
| 314 | |
| 315 | if (!targetIP) { |
| 316 | await msg.edit({ |
| 317 | text: |
| 318 | `❌ 请提供有效的IP地址\n\n支持的格式:\n` + |
| 319 | `• .bgp dns 1.1.1.1\n` + |
| 320 | `• .bgp dns 1.1.1.0/24\n` + |
| 321 | `• 回复包含IP的消息使用 .bgp dns`, |
| 322 | parseMode: "html", |
| 323 | }); |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | await msg.edit({ text: `🔍 正在查询DNS解析记录...`, parseMode: "html" }); |
| 328 | |
| 329 | try { |
| 330 | const result = await fetchDnsWithFallback(targetIP); |
| 331 | |
| 332 | let output = "A\tDNS\n"; |
| 333 | output += result.dnsLines.join("\n"); |
| 334 | |
| 335 | const formattedOutput = |
nothing calls this directly
no test coverage detected