MetaQiu commited on
Commit ·
cc76817
1
Parent(s): 57152db
feat
Browse files2 unmodified lines3456789101112131415161718192021222324252627282930313 unmodified lines35363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731743 unmodified lines1781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303315 unmodified lines3373383393403413423433443453463473483493503513523533543553563573583593603613623633643654 unmodified lines3703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354361 unmodified line4384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436444 unmodified lines64965065165265365465565665765865966066166266366466566666766866967014 unmodified lines6856866876886896906916923 unmodified lines6966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638642 unmodified lines8678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119122 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>IP 地理位置查询</title><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet"><style>:root {--bg-primary: #0a0e17;--bg-secondary: #111827;--bg-card: #1a2234;--accent: #00d4aa;--accent-dim: #00a88a;--text-primary: #e2e8f0;--text-secondary: #94a3b8;--text-muted: #64748b;--border: #2d3a4f;--glow: rgba(0, 212, 170, 0.15);}* {margin: 0;padding: 0;box-sizing: border-box;}body {font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;3 unmodified linesdisplay: flex;flex-direction: column;align-items: center;justify-content: center;overflow-x: hidden;}/* 背景网格动画 */.bg-grid {position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-image:linear-gradient(rgba(0, 212, 170, 0.03) 1px, transparent 1px),linear-gradient(90deg, rgba(0, 212, 170, 0.03) 1px, transparent 1px);background-size: 50px 50px;z-index: -1;}.bg-glow {position: fixed;top: -50%;left: -50%;width: 200%;height: 200%;background: radial-gradient(circle at 30% 20%, rgba(0, 212, 170, 0.08) 0%, transparent 40%),radial-gradient(circle at 70% 80%, rgba(59, 130, 246, 0.06) 0%, transparent 40%);z-index: -1;animation: bgFloat 20s ease-in-out infinite;}@keyframes bgFloat {0%, 100% { transform: translate(0, 0); }50% { transform: translate(-5%, 5%); }}.container {width: 100%;max-width: 800px;padding: 20px;display: flex;flex-direction: column;gap: 30px;position: relative;z-index: 1;}/* 头部 */header {text-align: center;margin-bottom: 20px;animation: fadeInDown 0.8s ease-out;}@keyframes fadeInDown {from { opacity: 0; transform: translateY(-20px); }to { opacity: 1; transform: translateY(0); }}.logo {font-size: 3.5rem;margin-bottom: 15px;filter: drop-shadow(0 0 30px var(--glow));display: inline-block;animation: float 6s ease-in-out infinite;}@keyframes float {0%, 100% { transform: translateY(0); }50% { transform: translateY(-10px); }}h1 {font-size: 2.5rem;font-weight: 700;background: linear-gradient(135deg, var(--accent) 0%, #3b82f6 100%);-webkit-background-clip: text;-webkit-text-fill-color: transparent;background-clip: text;margin-bottom: 10px;letter-spacing: -0.5px;}.subtitle {color: var(--text-secondary);font-size: 1.1rem;font-weight: 300;max-width: 600px;margin: 0 auto;line-height: 1.6;}/* 搜索框 */.search-section {animation: fadeInUp 0.8s ease-out 0.2s backwards;position: relative;z-index: 10;}@keyframes fadeInUp {from { opacity: 0; transform: translateY(20px); }to { opacity: 1; transform: translateY(0); }}.search-box-wrapper {background: rgba(26, 34, 52, 0.8);backdrop-filter: blur(12px);padding: 8px;border-radius: 20px;border: 1px solid var(--border);box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);display: flex;align-items: center;gap: 10px;}.search-box-wrapper:focus-within {border-color: var(--accent);box-shadow: 0 12px 40px rgba(0, 212, 170, 0.15), 0 0 0 1px var(--glow);transform: translateY(-2px);}.search-icon {padding-left: 16px;font-size: 1.2rem;color: var(--text-muted);}.search-input {flex: 1;background: transparent;border: none;padding: 18px 0;font-size: 1.15rem;color: var(--text-primary);font-family: 'JetBrains Mono', monospace;outline: none;3 unmodified lines.search-input::placeholder {color: var(--text-muted);font-family: 'Noto Sans SC', sans-serif;}.search-actions {display: flex;gap: 8px;padding-right: 8px;}.action-btn {background: var(--bg-secondary);border: 1px solid var(--border);padding: 10px 16px;border-radius: 12px;color: var(--text-secondary);font-size: 0.9rem;cursor: pointer;transition: all 0.2s ease;white-space: nowrap;display: flex;align-items: center;gap: 6px;}.action-btn:hover {background: var(--bg-card);color: var(--accent);border-color: var(--accent);}.search-btn {background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);border: none;padding: 10px 24px;border-radius: 12px;color: var(--bg-primary);font-size: 0.95rem;font-weight: 600;cursor: pointer;transition: all 0.3s ease;display: flex;align-items: center;justify-content: center;min-width: 80px;}.search-btn:hover {filter: brightness(1.1);box-shadow: 0 4px 12px rgba(0, 212, 170, 0.3);}.search-btn:active {transform: scale(0.98);}.search-btn.loading {pointer-events: none;opacity: 0.8;}.spinner {width: 18px;height: 18px;border: 2.5px solid rgba(10, 14, 23, 0.3);border-top-color: var(--bg-primary);border-radius: 50%;animation: spin 0.8s linear infinite;display: none;}.search-btn.loading .spinner {display: block;}.search-btn.loading .btn-text {display: none;}@keyframes spin {to { transform: rotate(360deg); }}/* 结果展示 */.result-section {margin-top: 20px;perspective: 1000px;min-height: 300px; /* 占位防止抖动 */}.result-card {background: var(--bg-card);border: 1px solid var(--border);border-radius: 24px;overflow: hidden;box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.5);animation: flipIn 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);position: relative;}@keyframes flipIn {from { opacity: 0; transform: rotateX(10deg) translateY(20px); }to { opacity: 1; transform: rotateX(0) translateY(0); }}/* 装饰光 */.result-card::before {content: '';position: absolute;top: 0;left: 0;right: 0;height: 1px;background: linear-gradient(90deg, transparent, var(--accent), transparent);opacity: 0.5;}.result-header {padding: 30px 40px;background: linear-gradient(180deg, rgba(0, 212, 170, 0.05) 0%, transparent 100%);display: flex;flex-direction: column;align-items: center;gap: 10px;border-bottom: 1px solid var(--border);}.result-ip {font-family: 'JetBrains Mono', monospace;font-size: 2.2rem;font-weight: 700;color: var(--accent);letter-spacing: 1px;text-shadow: 0 0 30px rgba(0, 212, 170, 0.3);}.result-subnet {font-family: 'JetBrains Mono', monospace;color: var(--text-muted);font-size: 0.9rem;background: rgba(0, 0, 0, 0.2);padding: 4px 12px;border-radius: 12px;}.result-body {padding: 40px;display: grid;grid-template-columns: repeat(2, 1fr);gap: 30px;}.info-group {5 unmodified lines.info-item {display: flex;flex-direction: column;gap: 8px;}.info-label {color: var(--text-muted);font-size: 0.8rem;text-transform: uppercase;letter-spacing: 1px;display: flex;align-items: center;gap: 6px;}.info-value {font-size: 1.1rem;color: var(--text-primary);font-weight: 500;line-height: 1.4;}.info-value.mono {font-family: 'JetBrains Mono', monospace;}.info-value.highlight {color: var(--accent);4 unmodified linesdisplay: flex;flex-wrap: wrap;align-items: center;gap: 8px;}.loc-pill {background: rgba(0, 212, 170, 0.1);color: var(--accent);padding: 6px 12px;border-radius: 8px;font-size: 0.95rem;border: 1px solid rgba(0, 212, 170, 0.2);}.loc-sep {color: var(--text-muted);font-size: 0.8rem;}.map-btn {margin-top: auto;background: var(--bg-secondary);border: 1px dashed var(--border);border-radius: 12px;padding: 12px;text-align: center;color: var(--text-secondary);font-size: 0.9rem;cursor: pointer;transition: all 0.3s ease;}.map-btn:hover {border-color: var(--accent);color: var(--accent);}/* 地图展示 */.map-section {margin-top: 20px;display: none;animation: fadeInUp 0.6s ease-out;}.map-container {background: var(--bg-card);border: 1px solid var(--border);border-radius: 20px;overflow: hidden;box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.5);}.map-header {padding: 16px 24px;background: linear-gradient(180deg, rgba(0, 212, 170, 0.05) 0%, transparent 100%);border-bottom: 1px solid var(--border);display: flex;align-items: center;gap: 8px;color: var(--text-secondary);font-size: 0.9rem;}.map-frame {width: 100%;height: 400px;1 unmodified linedisplay: block;}@media (max-width: 768px) {.map-frame {height: 300px;}}/* 错误状态 */.error-state {text-align: center;padding: 40px;background: rgba(239, 68, 68, 0.05);border: 1px solid rgba(239, 68, 68, 0.2);border-radius: 20px;color: #f87171;}/* 初始欢迎状态 */.welcome-state {text-align: center;padding: 60px 20px;color: var(--text-muted);font-weight: 300;animation: fadeIn 1s ease-out;}@keyframes fadeIn {from { opacity: 0; }to { opacity: 1; }}/* 页脚 */footer {margin-top: auto;padding: 30px;text-align: center;color: var(--text-muted);font-size: 0.8rem;opacity: 0.6;}/* 移动端适配 */@media (max-width: 768px) {.container { padding: 15px; }.logo { font-size: 2.5rem; }h1 { font-size: 1.8rem; }.search-box-wrapper {flex-direction: column;padding: 12px;gap: 12px;}.search-icon { display: none; }.search-input {padding: 10px;text-align: center;width: 100%;}.search-actions {width: 100%;justify-content: center;padding: 0;}.action-btn, .search-btn {flex: 1;justify-content: center;}.result-body {grid-template-columns: 1fr;padding: 25px;gap: 25px;}.result-ip { font-size: 1.6rem; }}.hidden { display: none !important; }/* API 文档样式 */.api-docs {background: var(--bg-card);border: 1px solid var(--border);border-radius: 20px;padding: 30px;width: 100%;margin-top: 20px;}.docs-title {font-size: 1.2rem;margin-bottom: 20px;color: var(--text-primary);display: flex;align-items: center;gap: 10px;}.code-block {background: #0f131a;border: 1px solid var(--border);border-radius: 12px;padding: 0;margin-bottom: 15px;overflow: hidden;}.code-block:last-child {margin-bottom: 0;}.code-header {background: rgba(255, 255, 255, 0.03);padding: 8px 16px;display: flex;justify-content: space-between;align-items: center;border-bottom: 1px solid var(--border);}.code-lang {font-size: 0.8rem;color: var(--text-muted);font-weight: 600;}.copy-btn {background: transparent;border: 1px solid var(--border);color: var(--text-secondary);padding: 4px 10px;border-radius: 6px;font-size: 0.75rem;cursor: pointer;transition: all 0.2s;}.copy-btn:hover {border-color: var(--accent);color: var(--accent);}code {display: block;padding: 16px;font-family: 'JetBrains Mono', monospace;font-size: 0.9rem;color: #a5b3ce;overflow-x: auto;white-space: pre;}.credits {margin-top: 10px;font-size: 0.9rem;}.credits a {color: var(--accent);text-decoration: none;transition: color 0.2s;}.credits a:hover {color: #fff;text-decoration: underline;}</style></head><body><div class="bg-grid"></div><div class="bg-glow"></div><div class="container"><header><div class="logo">🌍</div><h1>IP Geo API</h1><p class="subtitle">全球 IP 地理位置与归属地查询服务</p></header><section class="search-section"><div class="search-box-wrapper"><span class="search-icon">🔍</span><inputtype="text"class="search-input"id="ipInput"placeholder="输入 IP 地址..."autocomplete="off"spellcheck="false"><div class="search-actions"><button class="action-btn" onclick="queryMyIP()" title="查询本机IP"><span>📍</span><span class="btn-label">我的 IP</span></button><button class="search-btn" id="searchBtn" onclick="queryIP()"><span class="btn-text">查询</span><div class="spinner"></div></button>4 unmodified lines<section class="result-section" id="resultSection"><div class="welcome-state"><p>输入 IP 地址开始查询</p><p style="font-size: 0.9rem; margin-top: 10px; opacity: 0.7;">支持 IPv4 和 IPv6</p></div></section><section class="map-section" id="mapSection"><div class="map-container"><div class="map-header"><span>🗺️</span><span>位置标注</span></div><iframe class="map-frame" id="mapFrame" sandbox="allow-scripts allow-same-origin"></iframe></div></section><section class="api-docs"><h2 class="docs-title">🛠️ API 使用说明</h2><div class="code-block"><div class="code-header"><span class="code-lang">Shell</span>14 unmodified lines</div><footer><p>Powered by MaxMind GeoLite2 & GeoCN</p><p class="credits">Made with <span style="color: #ef4444;">❤</span> by <a href="https://metaqiu.cn" target="_blank">MetaQiu</a></p></footer><script>3 unmodified linesconst mapSection = document.getElementById('mapSection');const mapFrame = document.getElementById('mapFrame');// WGS84 → GCJ02 坐标转换function outOfChina(lng, lat) {return lng < 72.004 || lng > 137.8347 || lat < 0.8293 || lat > 55.8271;}function transformLat(x, y) {let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;ret += (20.0 * Math.sin(y * Math.PI) + 40.0 * Math.sin(y / 3.0 * Math.PI)) * 2.0 / 3.0;ret += (160.0 * Math.sin(y / 12.0 * Math.PI) + 320 * Math.sin(y * Math.PI / 30.0)) * 2.0 / 3.0;return ret;}function transformLng(x, y) {let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;ret += (20.0 * Math.sin(x * Math.PI) + 40.0 * Math.sin(x / 3.0 * Math.PI)) * 2.0 / 3.0;ret += (150.0 * Math.sin(x / 12.0 * Math.PI) + 300.0 * Math.sin(x / 30.0 * Math.PI)) * 2.0 / 3.0;return ret;}function wgs84ToGcj02(lng, lat) {const a = 6378245.0;const ee = 0.00669342162296594323;if (outOfChina(lng, lat)) return { lng, lat };let dLat = transformLat(lng - 105.0, lat - 35.0);let dLng = transformLng(lng - 105.0, lat - 35.0);const radLat = lat / 180.0 * Math.PI;let magic = Math.sin(radLat);magic = 1 - ee * magic * magic;const sqrtMagic = Math.sqrt(magic);dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * Math.PI);dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(radLat) * Math.PI);return { lat: lat + dLat, lng: lng + dLng };}function updateMap(lat, lng) {if (!lat || !lng) {mapSection.style.display = 'none';return;}const { lat: gcjLat, lng: gcjLng } = wgs84ToGcj02(parseFloat(lng), parseFloat(lat));const ak = 'nSxiPohfziUaCuONe4ViUP2N';mapFrame.src = `https://api.map.baidu.com/marker?location=${gcjLat},${gcjLng}&title=IP位置&content=IP位置&output=html&coord_type=gcj02&zoom=13&ak=${ak}`;mapSection.style.display = 'block';}// 复制代码功能function copyCode(type) {const el = document.getElementById(`code-${type}`);const text = el.innerText;navigator.clipboard.writeText(text).then(() => {const btn = el.parentElement.querySelector('.copy-btn');const originalText = btn.innerText;btn.innerText = '已复制!';setTimeout(() => btn.innerText = originalText, 2000);});}// 自动聚焦ipInput.focus();// 回车搜索ipInput.addEventListener('keypress', (e) => {if (e.key === 'Enter') queryIP();});// 页面加载时查询本机IPwindow.addEventListener('load', () => {queryMyIP();});function queryMyIP() {ipInput.value = '';queryIP(true);}async function queryIP(isMyIP = false) {const ip = ipInput.value.trim();// 如果不是查本机且输入为空,则不执行if (!isMyIP && !ip) return;const url = (!ip || isMyIP) ? '/api/' : `/api/${ip}`;searchBtn.classList.add('loading');try {const start = Date.now();const response = await fetch(url);const data = await response.json();// 保证最少loading时间,防止闪烁const elapsed = Date.now() - start;if (elapsed < 300) await new Promise(r => setTimeout(r, 300 - elapsed));if (data.error) {showError(data.error);} else {// 如果是查本机,自动填入IP框if (isMyIP && data.ip) {ipInput.value = data.ip;}showResult(data);}} catch (error) {showError('无法连接到服务器,请检��网络');} finally {searchBtn.classList.remove('loading');}}function showError(message) {mapSection.style.display = 'none';resultSection.innerHTML = `<div class="error-state"><div style="font-size: 2rem; margin-bottom: 10px;">⚠️</div><div>${message}</div></div>`;}function showResult(data) {// 构建位置路径let locationHtml = '<span style="color: var(--text-muted)">未知位置</span>';if (data.country || data.regions) {const parts = [];if (data.country) parts.push(data.country.name);if (data.regions) parts.push(...data.regions);locationHtml = parts.map(p => `<span class="loc-pill">${p}</span>`).join('<span class="loc-sep">›</span>');}// 构建ISP信息let ispName = '未知';let asn = 'N/A';let ispType = '';if (data.as) {ispName = data.as.info || data.as.name;asn = `AS${data.as.number}`;if (data.type) ispType = `<span class="result-subnet" style="margin-left: 8px">${data.type}</span>`;}// 注册地检查let regCountryHtml = '';if (data.registered_country && (!data.country || data.registered_country.code !== data.country.code)) {regCountryHtml = `<div class="info-item"><div class="info-label">📋 注册地</div><div class="info-value">${data.registered_country.name}</div></div>`;}// 经纬度let coordsHtml = '';if (data.location) {coordsHtml = `<div class="map-btn" onclick="updateMap(${data.location.latitude}, ${data.location.longitude})">📍 ${data.location.latitude}, ${data.location.longitude}</div>`;}resultSection.innerHTML = `2 unmodified lines<div class="result-ip">${data.ip}</div><div class="result-subnet">${data.addr || '未知网段'}</div></div><div class="result-body"><div class="info-group"><div class="info-item"><div class="info-label">🌍 地理位置</div><div class="location-path">${locationHtml}</div></div>${regCountryHtml}${coordsHtml}</div><div class="info-group"><div class="info-item"><div class="info-label">🏢 运营商 / ISP</div><div class="info-value highlight">${ispName}${ispType}</div></div><div class="info-item"><div class="info-label">🔢 ASN</div><div class="info-value mono">${asn}</div></div>${data.as && data.as.name !== ispName ? `<div class="info-item"><div class="info-label">🏷️ 组织名称</div><div class="info-value">${data.as.name}</div></div>` : ''}</div></div></div>`;// 自动显示地图if (data.location) {updateMap(data.location.latitude, data.location.longitude);} else {mapSection.style.display = 'none';}}</script></body>2 unmodified lines345678910111213141516171819202122232425262728293031323334353 unmodified lines394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441453 unmodified lines1491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782795 unmodified lines2852862872882892902912922932942952962972982993003013023033043053063073083093103113123134 unmodified lines3183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863871 unmodified line3893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996004 unmodified lines60560660760860961061161261361461561661761861962062162262362462562662762862914 unmodified lines6446456466476486496506513 unmodified lines6556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877882 unmodified lines7917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238242 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>IP Geo API - IP 地理位置查询</title><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;600;700&display=swap" rel="stylesheet"><style>:root {--bg-primary: #f8fafc;--bg-card: #ffffff;--bg-code: #1e293b;--accent: #0891b2;--accent-light: #ecfeff;--accent-hover: #0e7490;--green: #059669;--green-light: #ecfdf5;--text-primary: #0f172a;--text-secondary: #475569;--text-muted: #94a3b8;--border: #e2e8f0;--border-focus: #0891b2;--shadow-sm: 0 1px 2px rgba(0,0,0,0.05);--shadow-md: 0 4px 12px rgba(0,0,0,0.08);--shadow-lg: 0 12px 32px rgba(0,0,0,0.1);--radius: 16px;--radius-sm: 10px;}* { margin: 0; padding: 0; box-sizing: border-box; }body {font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;3 unmodified linesdisplay: flex;flex-direction: column;align-items: center;line-height: 1.6;}.bg-pattern {position: fixed;inset: 0;background-image:radial-gradient(circle at 20% 20%, rgba(8,145,178,0.04) 0%, transparent 50%),radial-gradient(circle at 80% 80%, rgba(5,150,105,0.03) 0%, transparent 50%);z-index: -1;}.container {width: 100%;max-width: 800px;padding: 24px 20px;display: flex;flex-direction: column;gap: 24px;}/* Header */header {text-align: center;padding: 40px 0 8px;animation: fadeIn 0.6s ease-out;}.logo-icon {width: 56px;height: 56px;margin: 0 auto 16px;background: linear-gradient(135deg, var(--accent) 0%, var(--green) 100%);border-radius: 16px;display: flex;align-items: center;justify-content: center;box-shadow: 0 4px 16px rgba(8,145,178,0.25);}.logo-icon svg {width: 28px;height: 28px;color: white;}h1 {font-size: 2rem;font-weight: 700;color: var(--text-primary);margin-bottom: 8px;letter-spacing: -0.5px;}.subtitle {color: var(--text-secondary);font-size: 1rem;font-weight: 400;}@keyframes fadeIn {from { opacity: 0; transform: translateY(-12px); }to { opacity: 1; transform: translateY(0); }}/* Search */.search-section {animation: fadeIn 0.6s ease-out 0.1s backwards;}.search-box-wrapper {background: var(--bg-card);padding: 6px;border-radius: var(--radius);border: 1.5px solid var(--border);box-shadow: var(--shadow-md);transition: border-color 0.2s, box-shadow 0.2s;display: flex;align-items: center;gap: 8px;}.search-box-wrapper:focus-within {border-color: var(--border-focus);box-shadow: 0 0 0 3px rgba(8,145,178,0.1), var(--shadow-md);}.search-icon {padding-left: 14px;color: var(--text-muted);display: flex;}.search-icon svg { width: 20px; height: 20px; }.search-input {flex: 1;background: transparent;border: none;padding: 14px 0;font-size: 1.05rem;color: var(--text-primary);font-family: 'JetBrains Mono', monospace;outline: none;3 unmodified lines.search-input::placeholder {color: var(--text-muted);font-family: 'Noto Sans SC', sans-serif;font-weight: 400;}.search-actions {display: flex;gap: 6px;padding-right: 6px;}.action-btn {background: var(--bg-primary);border: 1px solid var(--border);padding: 10px 14px;border-radius: var(--radius-sm);color: var(--text-secondary);font-size: 0.875rem;font-weight: 500;cursor: pointer;transition: all 0.2s;white-space: nowrap;display: flex;align-items: center;gap: 6px;}.action-btn svg { width: 16px; height: 16px; }.action-btn:hover {background: var(--accent-light);color: var(--accent);border-color: var(--accent);}.search-btn {background: var(--accent);border: none;padding: 10px 22px;border-radius: var(--radius-sm);color: white;font-size: 0.9rem;font-weight: 600;cursor: pointer;transition: all 0.2s;display: flex;align-items: center;justify-content: center;min-width: 76px;}.search-btn:hover {background: var(--accent-hover);box-shadow: 0 2px 8px rgba(8,145,178,0.3);}.search-btn:active { transform: scale(0.97); }.search-btn.loading { pointer-events: none; opacity: 0.7; }.spinner {width: 18px;height: 18px;border: 2.5px solid rgba(255,255,255,0.3);border-top-color: white;border-radius: 50%;animation: spin 0.7s linear infinite;display: none;}.search-btn.loading .spinner { display: block; }.search-btn.loading .btn-text { display: none; }@keyframes spin { to { transform: rotate(360deg); } }/* Results */.result-section {min-height: 200px;animation: fadeIn 0.4s ease-out;}.result-card {background: var(--bg-card);border: 1px solid var(--border);border-radius: var(--radius);overflow: hidden;box-shadow: var(--shadow-lg);animation: slideUp 0.4s ease-out;}@keyframes slideUp {from { opacity: 0; transform: translateY(16px); }to { opacity: 1; transform: translateY(0); }}.result-header {padding: 28px 32px;background: linear-gradient(135deg, var(--accent-light) 0%, #f0fdfa 100%);display: flex;flex-direction: column;align-items: center;gap: 8px;border-bottom: 1px solid var(--border);}.result-ip {font-family: 'JetBrains Mono', monospace;font-size: 2rem;font-weight: 700;color: var(--accent);letter-spacing: 0.5px;}.result-subnet {font-family: 'JetBrains Mono', monospace;color: var(--text-muted);font-size: 0.85rem;background: rgba(8,145,178,0.08);padding: 3px 12px;border-radius: 20px;}.result-body {padding: 32px;display: grid;grid-template-columns: repeat(2, 1fr);gap: 28px;}.info-group {5 unmodified lines.info-item {display: flex;flex-direction: column;gap: 6px;}.info-label {color: var(--text-muted);font-size: 0.75rem;font-weight: 600;text-transform: uppercase;letter-spacing: 0.5px;display: flex;align-items: center;gap: 6px;}.info-label svg { width: 14px; height: 14px; color: var(--accent); }.info-value {font-size: 1.05rem;color: var(--text-primary);font-weight: 500;}.info-value.mono { font-family: 'JetBrains Mono', monospace; }.info-value.highlight {color: var(--accent);4 unmodified linesdisplay: flex;flex-wrap: wrap;align-items: center;gap: 6px;}.loc-pill {background: var(--accent-light);color: var(--accent-hover);padding: 4px 12px;border-radius: 6px;font-size: 0.9rem;font-weight: 500;}.loc-sep {color: var(--text-muted);font-size: 0.75rem;}.map-btn {margin-top: auto;background: var(--bg-primary);border: 1px dashed var(--border);border-radius: var(--radius-sm);padding: 10px;text-align: center;color: var(--text-secondary);font-size: 0.875rem;font-family: 'JetBrains Mono', monospace;cursor: pointer;transition: all 0.2s;}.map-btn:hover {border-color: var(--accent);color: var(--accent);background: var(--accent-light);}/* Map */.map-section {display: none;animation: slideUp 0.4s ease-out;}.map-container {background: var(--bg-card);border: 1px solid var(--border);border-radius: var(--radius);overflow: hidden;box-shadow: var(--shadow-md);}.map-header {padding: 12px 20px;border-bottom: 1px solid var(--border);display: flex;align-items: center;gap: 8px;color: var(--text-secondary);font-size: 0.875rem;font-weight: 500;}.map-header svg { width: 16px; height: 16px; color: var(--accent); }.map-frame {width: 100%;height: 400px;1 unmodified linedisplay: block;}/* Error */.error-state {text-align: center;padding: 40px;background: #fef2f2;border: 1px solid #fecaca;border-radius: var(--radius);color: #dc2626;}.error-state svg {width: 32px;height: 32px;margin: 0 auto 12px;color: #f87171;}/* Welcome */.welcome-state {text-align: center;padding: 48px 20px;color: var(--text-muted);font-weight: 400;}.welcome-state p:first-child { font-size: 1rem; }.welcome-state p:last-child { font-size: 0.85rem; margin-top: 8px; opacity: 0.7; }/* Footer */footer {margin-top: auto;padding: 32px 20px;text-align: center;color: var(--text-muted);font-size: 0.8rem;}.credits { margin-top: 6px; }.credits a {color: var(--accent);text-decoration: none;font-weight: 500;transition: color 0.2s;}.credits a:hover { color: var(--accent-hover); text-decoration: underline; }/* API Docs */.api-docs {background: var(--bg-card);border: 1px solid var(--border);border-radius: var(--radius);padding: 28px;box-shadow: var(--shadow-sm);}.docs-title {font-size: 1.05rem;font-weight: 600;margin-bottom: 16px;color: var(--text-primary);display: flex;align-items: center;gap: 8px;}.docs-title svg { width: 18px; height: 18px; color: var(--accent); }.code-block {background: var(--bg-code);border-radius: var(--radius-sm);margin-bottom: 12px;overflow: hidden;}.code-block:last-child { margin-bottom: 0; }.code-header {background: rgba(255,255,255,0.06);padding: 8px 16px;display: flex;justify-content: space-between;align-items: center;border-bottom: 1px solid rgba(255,255,255,0.08);}.code-lang {font-size: 0.75rem;color: #94a3b8;font-weight: 600;font-family: 'JetBrains Mono', monospace;}.copy-btn {background: rgba(255,255,255,0.08);border: none;color: #94a3b8;padding: 4px 10px;border-radius: 6px;font-size: 0.75rem;cursor: pointer;transition: all 0.2s;font-family: 'Noto Sans SC', sans-serif;}.copy-btn:hover {background: rgba(255,255,255,0.15);color: white;}code {display: block;padding: 14px 16px;font-family: 'JetBrains Mono', monospace;font-size: 0.85rem;color: #e2e8f0;overflow-x: auto;white-space: pre;line-height: 1.6;}/* Responsive */@media (max-width: 768px) {.container { padding: 16px; }header { padding: 24px 0 0; }h1 { font-size: 1.6rem; }.search-box-wrapper {flex-direction: column;padding: 10px;gap: 10px;}.search-icon { display: none; }.search-input {padding: 10px;text-align: center;width: 100%;}.search-actions {width: 100%;justify-content: center;padding: 0;}.action-btn, .search-btn {flex: 1;justify-content: center;}.result-body {grid-template-columns: 1fr;padding: 24px;gap: 20px;}.result-ip { font-size: 1.5rem; }.map-frame { height: 300px; }}/* Reduced motion */@media (prefers-reduced-motion: reduce) {*, *::before, *::after {animation-duration: 0.01ms !important;transition-duration: 0.01ms !important;}}.hidden { display: none !important; }</style></head><body><div class="bg-pattern"></div><div class="container"><header><div class="logo-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></svg></div><h1>IP Geo API</h1><p class="subtitle">IP 地理位置与归属地查询</p></header><section class="search-section"><div class="search-box-wrapper"><span class="search-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg></span><inputtype="text"class="search-input"id="ipInput"placeholder="输入 IP 地址..."autocomplete="off"spellcheck="false"aria-label="IP 地址输入"><div class="search-actions"><button class="action-btn" onclick="queryMyIP()" title="查询本机IP" aria-label="查询本机IP"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"/><circle cx="12" cy="10" r="3"/></svg><span class="btn-label">我的 IP</span></button><button class="search-btn" id="searchBtn" onclick="queryIP()" aria-label="查询"><span class="btn-text">查询</span><div class="spinner"></div></button>4 unmodified lines<section class="result-section" id="resultSection"><div class="welcome-state"><p>输入 IP 地址开始查询</p><p>支持 IPv4 和 IPv6</p></div></section><section class="map-section" id="mapSection"><div class="map-container"><div class="map-header"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="3 6 9 3 15 6 21 3 21 18 15 21 9 18 3 21"/><line x1="9" x2="9" y1="3" y2="18"/><line x1="15" x2="15" y1="6" y2="21"/></svg><span>位置标注</span></div><iframe class="map-frame" id="mapFrame" sandbox="allow-scripts allow-same-origin" title="地图"></iframe></div></section><section class="api-docs"><h2 class="docs-title"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 18 2 2 4-4"/><path d="M21 12V8.5C21 5.46 18.54 3 15.5 3h-7C5.46 3 3 5.46 3 8.5v7C3 18.54 5.46 21 8.5 21H12"/><path d="M8 8h8"/><path d="M8 12h4"/></svg>API 使用说明</h2><div class="code-block"><div class="code-header"><span class="code-lang">Shell</span>14 unmodified lines</div><footer><p>Powered by MaxMind GeoLite2 & GeoCN</p><p class="credits">Made by <a href="https://metaqiu.cn" target="_blank" rel="noopener">MetaQiu</a></p></footer><script>3 unmodified linesconst mapSection = document.getElementById('mapSection');const mapFrame = document.getElementById('mapFrame');// SVG icon helpersconst icons = {globe: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></svg>',building: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="2" width="16" height="20" rx="2" ry="2"/><path d="M9 22v-4h6v4"/><path d="M8 6h.01"/><path d="M16 6h.01"/><path d="M12 6h.01"/><path d="M12 10h.01"/><path d="M12 14h.01"/><path d="M16 10h.01"/><path d="M16 14h.01"/><path d="M8 10h.01"/><path d="M8 14h.01"/></svg>',hash: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" x2="20" y1="9" y2="9"/><line x1="4" x2="20" y1="15" y2="15"/><line x1="10" x2="8" y1="3" y2="21"/><line x1="16" x2="14" y1="3" y2="21"/></svg>',tag: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2H2v10l9.29 9.29c.94.94 2.48.94 3.42 0l6.58-6.58c.94-.94.94-2.48 0-3.42L12 2Z"/><path d="M7 7h.01"/></svg>',clipboard: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="8" height="4" x="8" y="2" rx="1" ry="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/></svg>',mapPin: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"/><circle cx="12" cy="10" r="3"/></svg>',alertTriangle: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>',};// WGS84 → GCJ02function outOfChina(lng, lat) {return lng < 72.004 || lng > 137.8347 || lat < 0.8293 || lat > 55.8271;}function transformLat(x, y) {let r = -100.0 + 2.0*x + 3.0*y + 0.2*y*y + 0.1*x*y + 0.2*Math.sqrt(Math.abs(x));r += (20.0*Math.sin(6.0*x*Math.PI) + 20.0*Math.sin(2.0*x*Math.PI)) * 2.0/3.0;r += (20.0*Math.sin(y*Math.PI) + 40.0*Math.sin(y/3.0*Math.PI)) * 2.0/3.0;r += (160.0*Math.sin(y/12.0*Math.PI) + 320*Math.sin(y*Math.PI/30.0)) * 2.0/3.0;return r;}function transformLng(x, y) {let r = 300.0 + x + 2.0*y + 0.1*x*x + 0.1*x*y + 0.1*Math.sqrt(Math.abs(x));r += (20.0*Math.sin(6.0*x*Math.PI) + 20.0*Math.sin(2.0*x*Math.PI)) * 2.0/3.0;r += (20.0*Math.sin(x*Math.PI) + 40.0*Math.sin(x/3.0*Math.PI)) * 2.0/3.0;r += (150.0*Math.sin(x/12.0*Math.PI) + 300.0*Math.sin(x/30.0*Math.PI)) * 2.0/3.0;return r;}function wgs84ToGcj02(lng, lat) {const a = 6378245.0, ee = 0.00669342162296594323;if (outOfChina(lng, lat)) return { lng, lat };let dLat = transformLat(lng - 105.0, lat - 35.0);let dLng = transformLng(lng - 105.0, lat - 35.0);const radLat = lat / 180.0 * Math.PI;let magic = Math.sin(radLat);magic = 1 - ee * magic * magic;const sq = Math.sqrt(magic);dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sq) * Math.PI);dLng = (dLng * 180.0) / (a / sq * Math.cos(radLat) * Math.PI);return { lat: lat + dLat, lng: lng + dLng };}function updateMap(lat, lng) {if (!lat || !lng) { mapSection.style.display = 'none'; return; }const c = wgs84ToGcj02(parseFloat(lng), parseFloat(lat));const ak = 'nSxiPohfziUaCuONe4ViUP2N';mapFrame.src = `https://api.map.baidu.com/marker?location=${c.lat},${c.lng}&title=IP位置&content=IP位置&output=html&coord_type=gcj02&zoom=13&ak=${ak}`;mapSection.style.display = 'block';}function copyCode(type) {const el = document.getElementById(`code-${type}`);navigator.clipboard.writeText(el.innerText).then(() => {const btn = el.parentElement.querySelector('.copy-btn');const orig = btn.innerText;btn.innerText = '已复制';setTimeout(() => btn.innerText = orig, 2000);});}ipInput.focus();ipInput.addEventListener('keypress', e => { if (e.key === 'Enter') queryIP(); });window.addEventListener('load', () => queryMyIP());function queryMyIP() { ipInput.value = ''; queryIP(true); }async function queryIP(isMyIP = false) {const ip = ipInput.value.trim();if (!isMyIP && !ip) return;const url = (!ip || isMyIP) ? '/api/' : `/api/${ip}`;searchBtn.classList.add('loading');try {const start = Date.now();const res = await fetch(url);const data = await res.json();const elapsed = Date.now() - start;if (elapsed < 300) await new Promise(r => setTimeout(r, 300 - elapsed));if (data.error) { showError(data.error); }else {if (isMyIP && data.ip) ipInput.value = data.ip;showResult(data);}} catch { showError('无法连接到服务器,请检查网络'); }finally { searchBtn.classList.remove('loading'); }}function showError(msg) {mapSection.style.display = 'none';resultSection.innerHTML = `<div class="error-state">${icons.alertTriangle}<div>${msg}</div></div>`;}function showResult(data) {let locationHtml = '<span style="color:var(--text-muted)">未知位置</span>';if (data.country || data.regions) {const parts = [];if (data.country) parts.push(data.country.name);if (data.regions) parts.push(...data.regions);locationHtml = parts.map(p => `<span class="loc-pill">${p}</span>`).join('<span class="loc-sep">/</span>');}let ispName = '未知', asn = 'N/A', ispType = '';if (data.as) {ispName = data.as.info || data.as.name;asn = `AS${data.as.number}`;if (data.type) ispType = `<span class="result-subnet" style="margin-left:6px">${data.type}</span>`;}let regHtml = '';if (data.registered_country && (!data.country || data.registered_country.code !== data.country.code)) {regHtml = `<div class="info-item"><div class="info-label">${icons.clipboard} 注册地</div><div class="info-value">${data.registered_country.name}</div></div>`;}let coordsHtml = '';if (data.location) {coordsHtml = `<div class="map-btn" onclick="updateMap(${data.location.latitude},${data.location.longitude})">${data.location.latitude}, ${data.location.longitude}</div>`;}resultSection.innerHTML = `2 unmodified lines<div class="result-ip">${data.ip}</div><div class="result-subnet">${data.addr || '未知网段'}</div></div><div class="result-body"><div class="info-group"><div class="info-item"><div class="info-label">${icons.globe} 地理位置</div><div class="location-path">${locationHtml}</div></div>${regHtml}${coordsHtml}</div><div class="info-group"><div class="info-item"><div class="info-label">${icons.building} 运营商 / ISP</div><div class="info-value highlight">${ispName}${ispType}</div></div><div class="info-item"><div class="info-label">${icons.hash} ASN</div><div class="info-value mono">${asn}</div></div>${data.as && data.as.name !== ispName ? `<div class="info-item"><div class="info-label">${icons.tag} 组织名称</div><div class="info-value">${data.as.name}</div></div>` : ''}</div></div></div>`;if (data.location) updateMap(data.location.latitude, data.location.longitude);else mapSection.style.display = 'none';}</script></body>
static/index.html+351-439