Spaces:
Runtime error

MetaQiu commited on
Commit
9e217ab
·
1 Parent(s): 2570377
Files changed (1) hide show
  1. static/index.html +324 -268
static/index.html CHANGED
@@ -32,6 +32,10 @@
32
  background: var(--bg-primary);
33
  color: var(--text-primary);
34
  min-height: 100vh;
 
 
 
 
35
  overflow-x: hidden;
36
  }
37
 
@@ -67,131 +71,176 @@
67
  }
68
 
69
  .container {
70
- max-width: 900px;
71
- margin: 0 auto;
72
- padding: 40px 20px;
 
 
 
 
 
73
  }
74
 
75
  /* 头部 */
76
  header {
77
  text-align: center;
78
- margin-bottom: 50px;
79
  animation: fadeInDown 0.8s ease-out;
80
  }
81
 
82
  @keyframes fadeInDown {
83
- from {
84
- opacity: 0;
85
- transform: translateY(-30px);
86
- }
87
- to {
88
- opacity: 1;
89
- transform: translateY(0);
90
- }
91
  }
92
 
93
  .logo {
94
- font-size: 3rem;
95
- margin-bottom: 10px;
96
- filter: drop-shadow(0 0 20px var(--glow));
 
 
 
 
 
 
 
97
  }
98
 
99
  h1 {
100
- font-size: 2rem;
101
  font-weight: 700;
102
  background: linear-gradient(135deg, var(--accent) 0%, #3b82f6 100%);
103
  -webkit-background-clip: text;
104
  -webkit-text-fill-color: transparent;
105
  background-clip: text;
106
  margin-bottom: 10px;
 
107
  }
108
 
109
  .subtitle {
110
  color: var(--text-secondary);
111
- font-size: 1rem;
112
  font-weight: 300;
 
 
 
113
  }
114
 
115
  /* 搜索框 */
116
  .search-section {
117
  animation: fadeInUp 0.8s ease-out 0.2s backwards;
 
 
118
  }
119
 
120
  @keyframes fadeInUp {
121
- from {
122
- opacity: 0;
123
- transform: translateY(30px);
124
- }
125
- to {
126
- opacity: 1;
127
- transform: translateY(0);
128
- }
129
  }
130
 
131
- .search-box {
132
- display: flex;
133
- gap: 12px;
134
- background: var(--bg-card);
135
  padding: 8px;
136
- border-radius: 16px;
137
  border: 1px solid var(--border);
138
- box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
139
- transition: all 0.3s ease;
 
 
 
140
  }
141
 
142
- .search-box:focus-within {
143
  border-color: var(--accent);
144
- box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3), 0 0 0 3px var(--glow);
 
 
 
 
 
 
 
145
  }
146
 
147
  .search-input {
148
  flex: 1;
149
  background: transparent;
150
  border: none;
151
- padding: 16px 20px;
152
- font-size: 1.1rem;
153
  color: var(--text-primary);
154
  font-family: 'JetBrains Mono', monospace;
155
  outline: none;
 
156
  }
157
 
158
  .search-input::placeholder {
159
  color: var(--text-muted);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  }
161
 
162
  .search-btn {
163
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
164
  border: none;
165
- padding: 16px 32px;
166
- border-radius: 10px;
167
  color: var(--bg-primary);
168
- font-size: 1rem;
169
  font-weight: 600;
170
  cursor: pointer;
171
  transition: all 0.3s ease;
172
  display: flex;
173
  align-items: center;
174
- gap: 8px;
 
175
  }
176
 
177
  .search-btn:hover {
178
- transform: translateY(-2px);
179
- box-shadow: 0 8px 25px rgba(0, 212, 170, 0.4);
180
  }
181
 
182
  .search-btn:active {
183
- transform: translateY(0);
184
  }
185
 
186
  .search-btn.loading {
187
  pointer-events: none;
188
- opacity: 0.7;
189
  }
190
 
191
- .search-btn .spinner {
192
  width: 18px;
193
  height: 18px;
194
- border: 2px solid transparent;
195
  border-top-color: var(--bg-primary);
196
  border-radius: 50%;
197
  animation: spin 0.8s linear infinite;
@@ -210,113 +259,102 @@
210
  to { transform: rotate(360deg); }
211
  }
212
 
213
- /* 快捷操作 */
214
- .quick-actions {
215
- display: flex;
216
- gap: 10px;
217
- margin-top: 16px;
218
- flex-wrap: wrap;
219
- justify-content: center;
220
- }
221
-
222
- .quick-btn {
223
- background: var(--bg-secondary);
224
- border: 1px solid var(--border);
225
- padding: 8px 16px;
226
- border-radius: 8px;
227
- color: var(--text-secondary);
228
- font-size: 0.85rem;
229
- cursor: pointer;
230
- transition: all 0.2s ease;
231
- }
232
-
233
- .quick-btn:hover {
234
- background: var(--bg-card);
235
- color: var(--accent);
236
- border-color: var(--accent);
237
- }
238
-
239
- /* 结果区域 */
240
  .result-section {
241
- margin-top: 40px;
242
- animation: fadeInUp 0.5s ease-out;
 
243
  }
244
 
245
  .result-card {
246
  background: var(--bg-card);
247
  border: 1px solid var(--border);
248
- border-radius: 20px;
249
  overflow: hidden;
250
- box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  }
252
 
253
  .result-header {
254
- background: linear-gradient(135deg, rgba(0, 212, 170, 0.1) 0%, rgba(59, 130, 246, 0.1) 100%);
255
- padding: 24px 30px;
256
- border-bottom: 1px solid var(--border);
257
  display: flex;
 
258
  align-items: center;
259
- justify-content: space-between;
 
260
  }
261
 
262
  .result-ip {
263
  font-family: 'JetBrains Mono', monospace;
264
- font-size: 1.8rem;
265
- font-weight: 600;
266
  color: var(--accent);
 
 
267
  }
268
 
269
- .result-badge {
270
- background: var(--bg-secondary);
271
- padding: 6px 14px;
272
- border-radius: 20px;
273
- font-size: 0.85rem;
274
- color: var(--text-secondary);
 
275
  }
276
 
277
  .result-body {
278
- padding: 30px;
 
 
 
279
  }
280
 
281
- .info-grid {
282
- display: grid;
283
- grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
284
  gap: 20px;
285
  }
286
 
287
  .info-item {
288
- background: var(--bg-secondary);
289
- padding: 20px;
290
- border-radius: 12px;
291
- border: 1px solid var(--border);
292
- transition: all 0.3s ease;
293
- }
294
-
295
- .info-item:hover {
296
- border-color: var(--accent);
297
- transform: translateY(-2px);
298
  }
299
 
300
  .info-label {
301
- display: flex;
302
- align-items: center;
303
- gap: 8px;
304
  color: var(--text-muted);
305
- font-size: 0.85rem;
306
- margin-bottom: 8px;
307
  text-transform: uppercase;
308
- letter-spacing: 0.5px;
309
- }
310
-
311
- .info-label .icon {
312
- font-size: 1rem;
313
  }
314
 
315
  .info-value {
316
  font-size: 1.1rem;
317
  color: var(--text-primary);
318
  font-weight: 500;
319
- word-break: break-all;
320
  }
321
 
322
  .info-value.mono {
@@ -325,11 +363,7 @@
325
 
326
  .info-value.highlight {
327
  color: var(--accent);
328
- }
329
-
330
- /* 位置信息特殊样式 */
331
- .location-full {
332
- grid-column: 1 / -1;
333
  }
334
 
335
  .location-path {
@@ -339,115 +373,114 @@
339
  gap: 8px;
340
  }
341
 
342
- .location-path span {
343
- background: linear-gradient(135deg, var(--accent), var(--accent-dim));
344
- color: var(--bg-primary);
345
- padding: 6px 14px;
346
- border-radius: 6px;
347
- font-weight: 500;
 
348
  }
349
 
350
- .location-path .separator {
351
- background: none;
352
  color: var(--text-muted);
353
- padding: 0;
354
  }
355
 
356
- /* 地图占位 */
357
- .map-placeholder {
358
- margin-top: 20px;
359
  background: var(--bg-secondary);
360
  border: 1px dashed var(--border);
361
  border-radius: 12px;
362
- height: 200px;
363
- display: flex;
364
- flex-direction: column;
365
- align-items: center;
366
- justify-content: center;
367
- color: var(--text-muted);
368
  }
369
 
370
- .map-placeholder .coords {
371
- font-family: 'JetBrains Mono', monospace;
372
  color: var(--accent);
373
- margin-top: 10px;
374
- font-size: 1.1rem;
375
  }
376
 
377
- /* 错误提示 */
378
- .error-card {
379
- background: rgba(239, 68, 68, 0.1);
380
- border: 1px solid rgba(239, 68, 68, 0.3);
381
- border-radius: 16px;
382
- padding: 30px;
383
  text-align: center;
 
 
 
 
 
384
  }
385
 
386
- .error-card .icon {
387
- font-size: 3rem;
388
- margin-bottom: 15px;
 
 
 
 
389
  }
390
 
391
- .error-card .message {
392
- color: #f87171;
393
- font-size: 1.1rem;
394
  }
395
 
396
  /* 页脚 */
397
  footer {
 
 
398
  text-align: center;
399
- margin-top: 60px;
400
- padding: 20px;
401
  color: var(--text-muted);
402
- font-size: 0.85rem;
 
403
  }
404
 
405
- footer a {
406
- color: var(--accent);
407
- text-decoration: none;
408
- }
409
-
410
- footer a:hover {
411
- text-decoration: underline;
412
- }
413
-
414
- /* 响应式 */
415
- @media (max-width: 640px) {
416
- .container {
417
- padding: 20px 15px;
418
- }
419
-
420
- h1 {
421
- font-size: 1.5rem;
422
- }
423
-
424
- .search-box {
425
- flex-direction: column;
426
- }
427
-
428
- .search-btn {
429
- justify-content: center;
430
- }
431
-
432
- .result-header {
433
  flex-direction: column;
 
434
  gap: 12px;
 
 
 
 
 
 
435
  text-align: center;
 
436
  }
437
-
438
- .result-ip {
439
- font-size: 1.4rem;
 
 
 
 
 
 
 
440
  }
441
 
442
- .info-grid {
443
  grid-template-columns: 1fr;
 
 
444
  }
 
 
445
  }
446
 
447
- /* 隐藏类 */
448
- .hidden {
449
- display: none !important;
450
- }
451
  </style>
452
  </head>
453
  <body>
@@ -457,168 +490,192 @@
457
  <div class="container">
458
  <header>
459
  <div class="logo">🌍</div>
460
- <h1>IP 地理位置查询</h1>
461
- <p class="subtitle">查询 IP 地址的地理位置、运营商等详细信息</p>
462
  </header>
463
 
464
  <section class="search-section">
465
- <div class="search-box">
 
466
  <input
467
  type="text"
468
  class="search-input"
469
  id="ipInput"
470
- placeholder="输入 IP 地址,如 8.8.8.8"
471
  autocomplete="off"
 
472
  >
473
- <button class="search-btn" id="searchBtn" onclick="queryIP()">
474
- <span class="btn-text">🔍 查询</span>
475
- <div class="spinner"></div>
476
- </button>
477
- </div>
478
- <div class="quick-actions">
479
- <button class="quick-btn" onclick="queryMyIP()">📍 查询我的IP</button>
480
- <button class="quick-btn" onclick="setIP('8.8.8.8')">Google DNS</button>
481
- <button class="quick-btn" onclick="setIP('1.1.1.1')">Cloudflare</button>
482
- <button class="quick-btn" onclick="setIP('223.5.5.5')">阿里云 DNS</button>
483
  </div>
484
  </section>
485
 
486
- <section class="result-section hidden" id="resultSection">
487
- <!-- 结果将动态插入这里 -->
 
 
 
488
  </section>
489
-
490
- <footer>
491
- <p>数据来源:MaxMind GeoLite2 & GeoCN</p>
492
- </footer>
493
  </div>
494
 
 
 
 
 
495
  <script>
496
  const ipInput = document.getElementById('ipInput');
497
  const searchBtn = document.getElementById('searchBtn');
498
  const resultSection = document.getElementById('resultSection');
499
 
 
 
 
500
  // 回车搜索
501
  ipInput.addEventListener('keypress', (e) => {
502
  if (e.key === 'Enter') queryIP();
503
  });
504
 
505
- // 页面加载时自动查询本机IP
506
  window.addEventListener('load', () => {
507
  queryMyIP();
508
  });
509
 
510
- function setIP(ip) {
511
- ipInput.value = ip;
512
- queryIP();
513
- }
514
-
515
  function queryMyIP() {
516
  ipInput.value = '';
517
- queryIP();
518
  }
519
 
520
- async function queryIP() {
521
  const ip = ipInput.value.trim();
522
- const url = ip ? `/api/${ip}` : '/api/';
 
 
 
523
 
524
  searchBtn.classList.add('loading');
525
 
526
  try {
 
527
  const response = await fetch(url);
528
  const data = await response.json();
529
 
 
 
 
 
530
  if (data.error) {
531
  showError(data.error);
532
  } else {
 
 
 
 
533
  showResult(data);
534
  }
535
  } catch (error) {
536
- showError('查询失败,请检查网络连接');
537
  } finally {
538
  searchBtn.classList.remove('loading');
539
  }
540
  }
541
 
542
  function showError(message) {
543
- resultSection.classList.remove('hidden');
544
  resultSection.innerHTML = `
545
- <div class="error-card">
546
- <div class="icon">❌</div>
547
- <div class="message">${message}</div>
548
  </div>
549
  `;
550
  }
551
 
552
  function showResult(data) {
553
- resultSection.classList.remove('hidden');
554
-
555
  // 构建位置路径
556
- let locationHtml = '';
 
557
  if (data.country || data.regions) {
558
  const parts = [];
559
  if (data.country) parts.push(data.country.name);
560
  if (data.regions) parts.push(...data.regions);
561
 
562
- locationHtml = parts.map(p => `<span>${p}</span>`).join('<span class="separator">›</span>');
563
  }
564
 
565
  // 构建ISP信息
566
- let ispInfo = '';
 
 
 
567
  if (data.as) {
568
- if (data.as.info) {
569
- ispInfo = data.as.info;
570
- if (data.type) ispInfo += ` (${data.type})`;
571
- } else {
572
- ispInfo = data.as.name;
573
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
574
  }
575
 
576
  resultSection.innerHTML = `
577
  <div class="result-card">
578
  <div class="result-header">
579
  <div class="result-ip">${data.ip}</div>
580
- <div class="result-badge">${data.addr || 'N/A'}</div>
581
  </div>
 
582
  <div class="result-body">
583
- <div class="info-grid">
584
- ${locationHtml ? `
585
- <div class="info-item location-full">
586
- <div class="info-label"><span class="icon">📍</span> 地理位置</div>
587
- <div class="info-value">
588
- <div class="location-path">${locationHtml}</div>
589
- </div>
590
- </div>
591
- ` : ''}
592
-
593
- ${data.as ? `
594
  <div class="info-item">
595
- <div class="info-label"><span class="icon">🏢</span> 运营商 / ISP</div>
596
- <div class="info-value highlight">${ispInfo}</div>
597
  </div>
 
 
 
 
 
598
  <div class="info-item">
599
- <div class="info-label"><span class="icon">🔢</span> ASN</div>
600
- <div class="info-value mono">AS${data.as.number}</div>
 
 
 
601
  </div>
602
  <div class="info-item">
603
- <div class="info-label"><span class="icon">🏷️</span> AS 名称</div>
604
- <div class="info-value">${data.as.name}</div>
605
  </div>
606
- ` : ''}
607
-
608
- ${data.registered_country && (!data.country || data.registered_country.code !== data.country.code) ? `
609
  <div class="info-item">
610
- <div class="info-label"><span class="icon">📋</span> 注册地</div>
611
- <div class="info-value">${data.registered_country.name}</div>
612
  </div>
613
  ` : ''}
614
  </div>
615
-
616
- ${data.location ? `
617
- <div class="map-placeholder">
618
- <div>🗺️ 经纬度坐标</div>
619
- <div class="coords">${data.location.latitude}, ${data.location.longitude}</div>
620
- </div>
621
- ` : ''}
622
  </div>
623
  </div>
624
  `;
@@ -626,4 +683,3 @@
626
  </script>
627
  </body>
628
  </html>
629
-
 
32
  background: var(--bg-primary);
33
  color: var(--text-primary);
34
  min-height: 100vh;
35
+ display: flex;
36
+ flex-direction: column;
37
+ align-items: center;
38
+ justify-content: center;
39
  overflow-x: hidden;
40
  }
41
 
 
71
  }
72
 
73
  .container {
74
+ width: 100%;
75
+ max-width: 800px;
76
+ padding: 20px;
77
+ display: flex;
78
+ flex-direction: column;
79
+ gap: 30px;
80
+ position: relative;
81
+ z-index: 1;
82
  }
83
 
84
  /* 头部 */
85
  header {
86
  text-align: center;
87
+ margin-bottom: 20px;
88
  animation: fadeInDown 0.8s ease-out;
89
  }
90
 
91
  @keyframes fadeInDown {
92
+ from { opacity: 0; transform: translateY(-20px); }
93
+ to { opacity: 1; transform: translateY(0); }
 
 
 
 
 
 
94
  }
95
 
96
  .logo {
97
+ font-size: 3.5rem;
98
+ margin-bottom: 15px;
99
+ filter: drop-shadow(0 0 30px var(--glow));
100
+ display: inline-block;
101
+ animation: float 6s ease-in-out infinite;
102
+ }
103
+
104
+ @keyframes float {
105
+ 0%, 100% { transform: translateY(0); }
106
+ 50% { transform: translateY(-10px); }
107
  }
108
 
109
  h1 {
110
+ font-size: 2.5rem;
111
  font-weight: 700;
112
  background: linear-gradient(135deg, var(--accent) 0%, #3b82f6 100%);
113
  -webkit-background-clip: text;
114
  -webkit-text-fill-color: transparent;
115
  background-clip: text;
116
  margin-bottom: 10px;
117
+ letter-spacing: -0.5px;
118
  }
119
 
120
  .subtitle {
121
  color: var(--text-secondary);
122
+ font-size: 1.1rem;
123
  font-weight: 300;
124
+ max-width: 600px;
125
+ margin: 0 auto;
126
+ line-height: 1.6;
127
  }
128
 
129
  /* 搜索框 */
130
  .search-section {
131
  animation: fadeInUp 0.8s ease-out 0.2s backwards;
132
+ position: relative;
133
+ z-index: 10;
134
  }
135
 
136
  @keyframes fadeInUp {
137
+ from { opacity: 0; transform: translateY(20px); }
138
+ to { opacity: 1; transform: translateY(0); }
 
 
 
 
 
 
139
  }
140
 
141
+ .search-box-wrapper {
142
+ background: rgba(26, 34, 52, 0.8);
143
+ backdrop-filter: blur(12px);
 
144
  padding: 8px;
145
+ border-radius: 20px;
146
  border: 1px solid var(--border);
147
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
148
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
149
+ display: flex;
150
+ align-items: center;
151
+ gap: 10px;
152
  }
153
 
154
+ .search-box-wrapper:focus-within {
155
  border-color: var(--accent);
156
+ box-shadow: 0 12px 40px rgba(0, 212, 170, 0.15), 0 0 0 1px var(--glow);
157
+ transform: translateY(-2px);
158
+ }
159
+
160
+ .search-icon {
161
+ padding-left: 16px;
162
+ font-size: 1.2rem;
163
+ color: var(--text-muted);
164
  }
165
 
166
  .search-input {
167
  flex: 1;
168
  background: transparent;
169
  border: none;
170
+ padding: 18px 0;
171
+ font-size: 1.15rem;
172
  color: var(--text-primary);
173
  font-family: 'JetBrains Mono', monospace;
174
  outline: none;
175
+ min-width: 0;
176
  }
177
 
178
  .search-input::placeholder {
179
  color: var(--text-muted);
180
+ font-family: 'Noto Sans SC', sans-serif;
181
+ }
182
+
183
+ .search-actions {
184
+ display: flex;
185
+ gap: 8px;
186
+ padding-right: 8px;
187
+ }
188
+
189
+ .action-btn {
190
+ background: var(--bg-secondary);
191
+ border: 1px solid var(--border);
192
+ padding: 10px 16px;
193
+ border-radius: 12px;
194
+ color: var(--text-secondary);
195
+ font-size: 0.9rem;
196
+ cursor: pointer;
197
+ transition: all 0.2s ease;
198
+ white-space: nowrap;
199
+ display: flex;
200
+ align-items: center;
201
+ gap: 6px;
202
+ }
203
+
204
+ .action-btn:hover {
205
+ background: var(--bg-card);
206
+ color: var(--accent);
207
+ border-color: var(--accent);
208
  }
209
 
210
  .search-btn {
211
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
212
  border: none;
213
+ padding: 10px 24px;
214
+ border-radius: 12px;
215
  color: var(--bg-primary);
216
+ font-size: 0.95rem;
217
  font-weight: 600;
218
  cursor: pointer;
219
  transition: all 0.3s ease;
220
  display: flex;
221
  align-items: center;
222
+ justify-content: center;
223
+ min-width: 80px;
224
  }
225
 
226
  .search-btn:hover {
227
+ filter: brightness(1.1);
228
+ box-shadow: 0 4px 12px rgba(0, 212, 170, 0.3);
229
  }
230
 
231
  .search-btn:active {
232
+ transform: scale(0.98);
233
  }
234
 
235
  .search-btn.loading {
236
  pointer-events: none;
237
+ opacity: 0.8;
238
  }
239
 
240
+ .spinner {
241
  width: 18px;
242
  height: 18px;
243
+ border: 2.5px solid rgba(10, 14, 23, 0.3);
244
  border-top-color: var(--bg-primary);
245
  border-radius: 50%;
246
  animation: spin 0.8s linear infinite;
 
259
  to { transform: rotate(360deg); }
260
  }
261
 
262
+ /* 结果展示 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  .result-section {
264
+ margin-top: 20px;
265
+ perspective: 1000px;
266
+ min-height: 300px; /* 占位防止抖动 */
267
  }
268
 
269
  .result-card {
270
  background: var(--bg-card);
271
  border: 1px solid var(--border);
272
+ border-radius: 24px;
273
  overflow: hidden;
274
+ box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.5);
275
+ animation: flipIn 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
276
+ position: relative;
277
+ }
278
+
279
+ @keyframes flipIn {
280
+ from { opacity: 0; transform: rotateX(10deg) translateY(20px); }
281
+ to { opacity: 1; transform: rotateX(0) translateY(0); }
282
+ }
283
+
284
+ /* 装饰光 */
285
+ .result-card::before {
286
+ content: '';
287
+ position: absolute;
288
+ top: 0;
289
+ left: 0;
290
+ right: 0;
291
+ height: 1px;
292
+ background: linear-gradient(90deg, transparent, var(--accent), transparent);
293
+ opacity: 0.5;
294
  }
295
 
296
  .result-header {
297
+ padding: 30px 40px;
298
+ background: linear-gradient(180deg, rgba(0, 212, 170, 0.05) 0%, transparent 100%);
 
299
  display: flex;
300
+ flex-direction: column;
301
  align-items: center;
302
+ gap: 10px;
303
+ border-bottom: 1px solid var(--border);
304
  }
305
 
306
  .result-ip {
307
  font-family: 'JetBrains Mono', monospace;
308
+ font-size: 2.2rem;
309
+ font-weight: 700;
310
  color: var(--accent);
311
+ letter-spacing: 1px;
312
+ text-shadow: 0 0 30px rgba(0, 212, 170, 0.3);
313
  }
314
 
315
+ .result-subnet {
316
+ font-family: 'JetBrains Mono', monospace;
317
+ color: var(--text-muted);
318
+ font-size: 0.9rem;
319
+ background: rgba(0, 0, 0, 0.2);
320
+ padding: 4px 12px;
321
+ border-radius: 12px;
322
  }
323
 
324
  .result-body {
325
+ padding: 40px;
326
+ display: grid;
327
+ grid-template-columns: repeat(2, 1fr);
328
+ gap: 30px;
329
  }
330
 
331
+ .info-group {
332
+ display: flex;
333
+ flex-direction: column;
334
  gap: 20px;
335
  }
336
 
337
  .info-item {
338
+ display: flex;
339
+ flex-direction: column;
340
+ gap: 8px;
 
 
 
 
 
 
 
341
  }
342
 
343
  .info-label {
 
 
 
344
  color: var(--text-muted);
345
+ font-size: 0.8rem;
 
346
  text-transform: uppercase;
347
+ letter-spacing: 1px;
348
+ display: flex;
349
+ align-items: center;
350
+ gap: 6px;
 
351
  }
352
 
353
  .info-value {
354
  font-size: 1.1rem;
355
  color: var(--text-primary);
356
  font-weight: 500;
357
+ line-height: 1.4;
358
  }
359
 
360
  .info-value.mono {
 
363
 
364
  .info-value.highlight {
365
  color: var(--accent);
366
+ font-weight: 600;
 
 
 
 
367
  }
368
 
369
  .location-path {
 
373
  gap: 8px;
374
  }
375
 
376
+ .loc-pill {
377
+ background: rgba(0, 212, 170, 0.1);
378
+ color: var(--accent);
379
+ padding: 6px 12px;
380
+ border-radius: 8px;
381
+ font-size: 0.95rem;
382
+ border: 1px solid rgba(0, 212, 170, 0.2);
383
  }
384
 
385
+ .loc-sep {
 
386
  color: var(--text-muted);
387
+ font-size: 0.8rem;
388
  }
389
 
390
+ .map-btn {
391
+ margin-top: auto;
 
392
  background: var(--bg-secondary);
393
  border: 1px dashed var(--border);
394
  border-radius: 12px;
395
+ padding: 12px;
396
+ text-align: center;
397
+ color: var(--text-secondary);
398
+ font-size: 0.9rem;
399
+ cursor: default;
400
+ transition: all 0.3s ease;
401
  }
402
 
403
+ .map-btn:hover {
404
+ border-color: var(--accent);
405
  color: var(--accent);
 
 
406
  }
407
 
408
+ /* 错误状态 */
409
+ .error-state {
 
 
 
 
410
  text-align: center;
411
+ padding: 40px;
412
+ background: rgba(239, 68, 68, 0.05);
413
+ border: 1px solid rgba(239, 68, 68, 0.2);
414
+ border-radius: 20px;
415
+ color: #f87171;
416
  }
417
 
418
+ /* 初始欢迎状态 */
419
+ .welcome-state {
420
+ text-align: center;
421
+ padding: 60px 20px;
422
+ color: var(--text-muted);
423
+ font-weight: 300;
424
+ animation: fadeIn 1s ease-out;
425
  }
426
 
427
+ @keyframes fadeIn {
428
+ from { opacity: 0; }
429
+ to { opacity: 1; }
430
  }
431
 
432
  /* 页脚 */
433
  footer {
434
+ margin-top: auto;
435
+ padding: 30px;
436
  text-align: center;
 
 
437
  color: var(--text-muted);
438
+ font-size: 0.8rem;
439
+ opacity: 0.6;
440
  }
441
 
442
+ /* 移动端适配 */
443
+ @media (max-width: 768px) {
444
+ .container { padding: 15px; }
445
+
446
+ .logo { font-size: 2.5rem; }
447
+ h1 { font-size: 1.8rem; }
448
+
449
+ .search-box-wrapper {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450
  flex-direction: column;
451
+ padding: 12px;
452
  gap: 12px;
453
+ }
454
+
455
+ .search-icon { display: none; }
456
+
457
+ .search-input {
458
+ padding: 10px;
459
  text-align: center;
460
+ width: 100%;
461
  }
462
+
463
+ .search-actions {
464
+ width: 100%;
465
+ justify-content: center;
466
+ padding: 0;
467
+ }
468
+
469
+ .action-btn, .search-btn {
470
+ flex: 1;
471
+ justify-content: center;
472
  }
473
 
474
+ .result-body {
475
  grid-template-columns: 1fr;
476
+ padding: 25px;
477
+ gap: 25px;
478
  }
479
+
480
+ .result-ip { font-size: 1.6rem; }
481
  }
482
 
483
+ .hidden { display: none !important; }
 
 
 
484
  </style>
485
  </head>
486
  <body>
 
490
  <div class="container">
491
  <header>
492
  <div class="logo">🌍</div>
493
+ <h1>IP Geo API</h1>
494
+ <p class="subtitle">全球 IP 地理位置与归属地查询服务</p>
495
  </header>
496
 
497
  <section class="search-section">
498
+ <div class="search-box-wrapper">
499
+ <span class="search-icon">🔍</span>
500
  <input
501
  type="text"
502
  class="search-input"
503
  id="ipInput"
504
+ placeholder="输入 IP 地址..."
505
  autocomplete="off"
506
+ spellcheck="false"
507
  >
508
+ <div class="search-actions">
509
+ <button class="action-btn" onclick="queryMyIP()" title="查询本机IP">
510
+ <span>📍</span>
511
+ <span class="btn-label">我的 IP</span>
512
+ </button>
513
+ <button class="search-btn" id="searchBtn" onclick="queryIP()">
514
+ <span class="btn-text">查询</span>
515
+ <div class="spinner"></div>
516
+ </button>
517
+ </div>
518
  </div>
519
  </section>
520
 
521
+ <section class="result-section" id="resultSection">
522
+ <div class="welcome-state">
523
+ <p>输入 IP 地址开始查询</p>
524
+ <p style="font-size: 0.9rem; margin-top: 10px; opacity: 0.7;">支持 IPv4 和 IPv6</p>
525
+ </div>
526
  </section>
 
 
 
 
527
  </div>
528
 
529
+ <footer>
530
+ <p>Powered by MaxMind GeoLite2 & GeoCN</p>
531
+ </footer>
532
+
533
  <script>
534
  const ipInput = document.getElementById('ipInput');
535
  const searchBtn = document.getElementById('searchBtn');
536
  const resultSection = document.getElementById('resultSection');
537
 
538
+ // 自动聚焦
539
+ ipInput.focus();
540
+
541
  // 回车搜索
542
  ipInput.addEventListener('keypress', (e) => {
543
  if (e.key === 'Enter') queryIP();
544
  });
545
 
546
+ // 页面加载时查询本机IP
547
  window.addEventListener('load', () => {
548
  queryMyIP();
549
  });
550
 
 
 
 
 
 
551
  function queryMyIP() {
552
  ipInput.value = '';
553
+ queryIP(true);
554
  }
555
 
556
+ async function queryIP(isMyIP = false) {
557
  const ip = ipInput.value.trim();
558
+ // 如果不是查本机且输入为空,则不执行
559
+ if (!isMyIP && !ip) return;
560
+
561
+ const url = (!ip || isMyIP) ? '/api/' : `/api/${ip}`;
562
 
563
  searchBtn.classList.add('loading');
564
 
565
  try {
566
+ const start = Date.now();
567
  const response = await fetch(url);
568
  const data = await response.json();
569
 
570
+ // 保证最少loading时间,防止闪烁
571
+ const elapsed = Date.now() - start;
572
+ if (elapsed < 300) await new Promise(r => setTimeout(r, 300 - elapsed));
573
+
574
  if (data.error) {
575
  showError(data.error);
576
  } else {
577
+ // 如果是查本机,自动填入IP框
578
+ if (isMyIP && data.ip) {
579
+ ipInput.value = data.ip;
580
+ }
581
  showResult(data);
582
  }
583
  } catch (error) {
584
+ showError('无法连接到服务器,请检查网络');
585
  } finally {
586
  searchBtn.classList.remove('loading');
587
  }
588
  }
589
 
590
  function showError(message) {
 
591
  resultSection.innerHTML = `
592
+ <div class="error-state">
593
+ <div style="font-size: 2rem; margin-bottom: 10px;">⚠️</div>
594
+ <div>${message}</div>
595
  </div>
596
  `;
597
  }
598
 
599
  function showResult(data) {
 
 
600
  // 构建位置路径
601
+ let locationHtml = '<span style="color: var(--text-muted)">未知位置</span>';
602
+
603
  if (data.country || data.regions) {
604
  const parts = [];
605
  if (data.country) parts.push(data.country.name);
606
  if (data.regions) parts.push(...data.regions);
607
 
608
+ locationHtml = parts.map(p => `<span class="loc-pill">${p}</span>`).join('<span class="loc-sep">›</span>');
609
  }
610
 
611
  // 构建ISP信息
612
+ let ispName = '未知';
613
+ let asn = 'N/A';
614
+ let ispType = '';
615
+
616
  if (data.as) {
617
+ ispName = data.as.info || data.as.name;
618
+ asn = `AS${data.as.number}`;
619
+ if (data.type) ispType = `<span class="result-subnet" style="margin-left: 8px">${data.type}</span>`;
620
+ }
621
+
622
+ // 注册地检查
623
+ let regCountryHtml = '';
624
+ if (data.registered_country && (!data.country || data.registered_country.code !== data.country.code)) {
625
+ regCountryHtml = `
626
+ <div class="info-item">
627
+ <div class="info-label">📋 注册地</div>
628
+ <div class="info-value">${data.registered_country.name}</div>
629
+ </div>
630
+ `;
631
+ }
632
+
633
+ // 经纬度
634
+ let coordsHtml = '';
635
+ if (data.location) {
636
+ coordsHtml = `
637
+ <div class="map-btn">
638
+ 📍 ${data.location.latitude}, ${data.location.longitude}
639
+ </div>
640
+ `;
641
  }
642
 
643
  resultSection.innerHTML = `
644
  <div class="result-card">
645
  <div class="result-header">
646
  <div class="result-ip">${data.ip}</div>
647
+ <div class="result-subnet">${data.addr || '未知网段'}</div>
648
  </div>
649
+
650
  <div class="result-body">
651
+ <div class="info-group">
 
 
 
 
 
 
 
 
 
 
652
  <div class="info-item">
653
+ <div class="info-label">🌍 地理位置</div>
654
+ <div class="location-path">${locationHtml}</div>
655
  </div>
656
+ ${regCountryHtml}
657
+ ${coordsHtml}
658
+ </div>
659
+
660
+ <div class="info-group">
661
  <div class="info-item">
662
+ <div class="info-label">🏢 运营商 / ISP</div>
663
+ <div class="info-value highlight">
664
+ ${ispName}
665
+ ${ispType}
666
+ </div>
667
  </div>
668
  <div class="info-item">
669
+ <div class="info-label">🔢 ASN</div>
670
+ <div class="info-value mono">${asn}</div>
671
  </div>
672
+ ${data.as && data.as.name !== ispName ? `
 
 
673
  <div class="info-item">
674
+ <div class="info-label">🏷️ 组织名称</div>
675
+ <div class="info-value">${data.as.name}</div>
676
  </div>
677
  ` : ''}
678
  </div>
 
 
 
 
 
 
 
679
  </div>
680
  </div>
681
  `;
 
683
  </script>
684
  </body>
685
  </html>