function formatBeijingTime() { const d = new Date(); // 转为北京时间 (UTC+8) const bj = new Date(d.getTime() + (8 * 60 * 60 * 1000)); const Y = bj.getUTCFullYear(); const M = String(bj.getUTCMonth() + 1).padStart(2, '0'); const D = String(bj.getUTCDate()).padStart(2, '0'); const h = String(bj.getUTCHours()).padStart(2, '0'); const m = String(bj.getUTCMinutes()).padStart(2, '0'); const s = String(bj.getUTCSeconds()).padStart(2, '0'); const ms = String(bj.getUTCMilliseconds()).padStart(3, '0'); return `${Y}-${M}-${D} ${h}:${m}:${s}.${ms} (UTC+8)`; } export default { async fetch(request, env, ctx) { const cf = request.cf || {}; const url = new URL(request.url); const UA = request.headers.get('User-Agent') || '未知'; const acceptLang = request.headers.get('Accept-Language') || ''; // ===== 速度测试端点 ===== if (url.pathname === '/speedtest') { // 返回 10MB 随机数据用于测速 const size = 10 * 1024 * 1024; // 10MB const chunk = new Uint8Array(1024 * 64); // 64KB chunk let sent = 0; const stream = new ReadableStream({ pull(controller) { if (sent >= size) { controller.close(); return; } const toSend = Math.min(chunk.byteLength, size - sent); controller.enqueue(new Uint8Array(chunk.buffer, 0, toSend)); sent += toSend; } }); return new Response(stream, { headers: { 'Content-Type': 'application/octet-stream', 'Cache-Control': 'no-store', 'Access-Control-Allow-Origin': '*', }, }); } // ===== 多语言判断 ===== const prefersChinese = /zh|zh-CN|zh-TW|zh-HK/i.test(acceptLang); const lang = prefersChinese ? 'zh' : 'en'; // ===== 获取客户端真实 IP ===== const rawIP = request.headers.get('CF-Connecting-IP') || request.headers.get('X-Forwarded-For') || request.headers.get('X-Real-IP') || '未知'; const clientIP = rawIP.split(',')[0].trim(); const isIPv6 = clientIP.includes(':'); const ipType = isIPv6 ? 'IPv6' : 'IPv4'; // ===== VPS/客户端环境检测 ===== const isTerminal = /curl|wget|python|go-http|libwww|okhttp|axios|node-fetch|requests/i.test(UA); const isBrowser = /Mozilla|Chrome|Safari|Firefox|Edge/i.test(UA) && !isTerminal; const isVPS = !isBrowser; // ===== 地理信息 ===== const country = cf.country || '未知'; const city = cf.city || '未知'; const region = cf.region || '未知'; const timezone = cf.timezone || 'UTC'; const colo = cf.colo || '未知'; const continent = cf.continent || '未知'; const postalCode = cf.postalCode || '未知'; const latitude = cf.latitude || '未知'; const longitude = cf.longitude || '未知'; // ===== 网络信息 ===== const asOrganization = cf.asOrganization || `AS${cf.asn}` || '未知'; const asn = cf.asn || '未知'; const httpProtocol = cf.httpProtocol || 'HTTP/2'; const tlsVersion = cf.tlsVersion || '未知'; const tlsCipher = cf.tlsCipher || '未知'; // ===== 客户端信息 ===== const botScore = cf.botManagement?.score ?? 'N/A'; const isTor = cf.isTor === true ? '是' : '否'; const isEU = cf.isEUCountry === '1' ? '是' : '否'; // ===== 判断环境类型 ===== let envType, envIcon; if (isTerminal) { envType = lang === 'zh' ? '终端/命令行' : 'Terminal/CLI'; envIcon = '💻'; } else if (isBrowser) { envType = lang === 'zh' ? '浏览器' : 'Browser'; envIcon = '🌐'; } else { envType = lang === 'zh' ? 'VPS/服务器' : 'VPS/Server'; envIcon = '🖥️'; } // ===== 设备/系统判断 ===== let os = '未知'; if (/Windows/i.test(UA)) os = 'Windows'; else if (/Mac OS/i.test(UA)) os = 'macOS'; else if (/Linux/i.test(UA) && !/Android/i.test(UA)) os = 'Linux'; else if (/Android/i.test(UA)) os = 'Android'; else if (/iPhone|iPad|iOS/i.test(UA)) os = 'iOS'; else if (/CrOS/i.test(UA)) os = 'ChromeOS'; // ===== 反向地理编码 ===== let geoAddress = null; if (latitude !== '未知' && longitude !== '未知') { try { const geoRes = await fetch( `https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=json&zoom=14&accept-language=${lang === 'zh' ? 'zh' : 'en'}`, { headers: { 'User-Agent': 'CloudflareWorker/1.0' } } ); if (geoRes.ok) { const geoData = await geoRes.json(); geoAddress = geoData.display_name || null; } } catch (e) { geoAddress = null; } } // ===== 响应处理 ===== if (isTerminal || isVPS) { const T = lang === 'zh' ? { title: '节点信息', domain: '访问域名', country: '访问国家/地区', city: '访问城市', region: '访问区域', continent: '访问大洲', postal: '邮政编码', coords: '经纬度', address: '具体地址', timezone: '时区', colo: 'Cloudflare 节点', network: '网络信息', ip: '客户端IP', asn: '运营商/ASN', tls: 'TLS 版本', cipher: 'TLS 加密套件', http: 'HTTP 协议', client: '客户端信息', env: '环境', os: '操作系统', ua: 'User-Agent', security: '安全信息', bot: '机器人评分', tor: '是否是 Tor', eu: '是否在欧盟', time: '查询时间', } : { title: 'Node Info', domain: 'Domain', country: 'Country', city: 'City', region: 'Region', continent: 'Continent', postal: 'Postal Code', coords: 'Coordinates', address: 'Address', timezone: 'Timezone', colo: 'CF Colo', network: 'Network', ip: 'Client IP', asn: 'ASN', tls: 'TLS Version', cipher: 'TLS Cipher', http: 'HTTP Protocol', client: 'Client', env: 'Environment', os: 'OS', ua: 'User-Agent', security: 'Security', bot: 'Bot Score', tor: 'Tor', eu: 'EU', time: 'Query Time', }; const text = [ `🔍 ${T.title} - ${url.hostname}`, ``, `🌍 ${T.domain}: ${url.hostname}`, `📍 ${T.country}: ${country}`, `🏙️ ${T.city}: ${city}`, `🏛️ ${T.region}: ${region}`, `🗺️ ${T.continent}: ${continent}`, `📮 ${T.postal}: ${postalCode}`, `🌐 ${T.coords}: ${latitude}, ${longitude}`, ...(geoAddress ? [`📍 ${T.address}: ${geoAddress}`] : []), `🕐 ${T.timezone}: ${timezone}`, `🖥️ ${T.colo}: ${colo}`, ``, `📡 ${T.network}:`, `🔗 ${T.ip}: ${clientIP} (${ipType})`, `🏢 ${T.asn}: ${asOrganization} (AS${asn})`, `🔒 ${T.tls}: ${tlsVersion}`, `🔑 ${T.cipher}: ${tlsCipher}`, `📶 ${T.http}: ${httpProtocol}`, ``, `🖥️ ${T.client}:`, `🔍 ${T.env}: ${envType}`, `💿 ${T.os}: ${os}`, `🧠 ${T.ua}: ${UA}`, ``, `🛡️ ${T.security}:`, `🤖 ${T.bot}: ${botScore}`, `🌐 ${T.tor}: ${isTor}`, `🇪🇺 ${T.eu}: ${isEU}`, ``, `⏰ ${T.time}: ${formatBeijingTime()}`, ].join('\n'); return new Response(text, { headers: { 'Content-Type': 'text/plain; charset=utf-8' }, }); } // 浏览器返回 HTML const html = generateHTML({ hostname: url.hostname, clientIP, ipType, country, city, region, continent, postalCode, latitude, longitude, timezone, colo, asOrganization, asn, httpProtocol, tlsVersion, tlsCipher, botScore, isTor, isEU, envType, envIcon, os, UA, geoAddress, lang, }); return new Response(html, { headers: { 'Content-Type': 'text/html; charset=utf-8' }, }); }, }; function esc(str) { return String(str).replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"').replace(/'/g,'''); } function generateHTML(data) { const { hostname, clientIP, ipType, country, city, region, continent, postalCode, latitude, longitude, timezone, colo, asOrganization, asn, httpProtocol, tlsVersion, tlsCipher, botScore, isTor, isEU, envType, envIcon, os, UA, geoAddress, lang, } = data; const hasCoords = latitude !== '未知' && longitude !== '未知'; const T = lang === 'zh' ? { title: '节点信息', subtitle: 'Cloudflare Workers', location: '📍 位置信息', domain: '🌍 域名', country: '🏳️ 国家/地区', city: '🏙️ 城市', region: '🏛️ 区域', continent: '🗺️ 大洲', postal: '📮 邮政编码', address: '📍 具体地址', coords: '🌐 经纬度', viewMap: '🗺️ 在 Google Maps 查看', timezone: '🕐 时区', colo: '🖥️ CF 节点', ipTitle: '🌐 IP 地址', cfIP: '☁️ CF 连接 IP', browserIPv4: '🌐 浏览器 IPv4', browserIPv6: '🌐 浏览器 IPv6', detecting: '检测中...', noIPv4: '无 IPv4', noIPv6: '无 IPv6', networkTitle: '📡 网络信息', asn: '🏢 运营商/ASN', tls: '🔒 TLS 版本', cipher: '🔑 TLS 加密', http: '📶 HTTP 协议', clientTitle: '🖥️ 客户端', env: '🔍 环境', os: '💿 操作系统', ua: '🧠 User-Agent', securityTitle: '🛡️ 安全', bot: '🤖 机器人评分', tor: '🌐 Tor', eu: '🇪🇺 欧盟', speedTitle: '⚡ 网络测速', latency: '🕐 延迟(RTT)', download: '📥 下载速度', testing: '测试中...', startTest: '▶️ 开始测速', testing2: '测试中...', copied: '✅ 已复制', copy: '📋 复制', footer: '查询时间', } : { title: 'Node Info', subtitle: 'Cloudflare Workers', location: '📍 Location', domain: '🌍 Domain', country: '🏳️ Country', city: '🏙️ City', region: '🏛️ Region', continent: '🗺️ Continent', postal: '📮 Postal Code', address: '📍 Address', coords: '🌐 Coordinates', viewMap: '🗺️ View on Google Maps', timezone: '🕐 Timezone', colo: '🖥️ CF Colo', ipTitle: '🌐 IP Address', cfIP: '☁️ CF Connecting IP', browserIPv4: '🌐 Browser IPv4', browserIPv6: '🌐 Browser IPv6', detecting: 'Detecting...', noIPv4: 'No IPv4', noIPv6: 'No IPv6', networkTitle: '📡 Network', asn: '🏢 ASN', tls: '🔒 TLS Version', cipher: '🔑 TLS Cipher', http: '📶 HTTP Protocol', clientTitle: '🖥️ Client', env: '🔍 Environment', os: '💿 OS', ua: '🧠 User-Agent', securityTitle: '🛡️ Security', bot: '🤖 Bot Score', tor: '🌐 Tor', eu: '🇪🇺 EU', speedTitle: '⚡ Speed Test', latency: '🕐 Latency (RTT)', download: '📥 Download Speed', testing: 'Testing...', startTest: '▶️ Start Test', testing2: 'Testing...', copied: '✅ Copied', copy: '📋 Copy', footer: 'Query Time', }; return `