'use client' import { useState } from 'react' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Alert, AlertDescription } from '@/components/ui/alert' import { Globe, ExternalLink, Info, CheckCircle, AlertCircle } from 'lucide-react' export default function IpTestPage() { const [externalIp, setExternalIp] = useState(null) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const fetchExternalIp = async () => { setLoading(true) setError(null) try { const response = await fetch('https://api.ipify.org?format=json') if (!response.ok) { throw new Error('無法獲取外部IP') } const data = await response.json() setExternalIp(data.ip) } catch (error) { console.error('Error fetching external IP:', error) setError('無法獲取外部IP地址') } finally { setLoading(false) } } return (

IP 測試工具

測試你的真實公網IP地址

{/* 說明 */}
為什麼會顯示 127.0.0.1?
• 在本地開發環境中,所有請求都來自本地回環地址
• 這是正常的行為,不是錯誤
• 在生產環境中部署後,IP檢測會更準確
• 你可以使用下面的工具測試你的真實公網IP
{/* 外部IP檢測 */} 真實公網IP檢測 從外部服務獲取你的真實公網IP地址
{externalIp && (
你的公網IP: {externalIp}
)}
{error && ( {error} )}

這個IP地址就是你的真實公網IP,可以用於:

  • 配置IP白名單
  • 測試IP檢測功能
  • 驗證網路配置
{/* 測試方法 */} 測試真實IP的方法 幾種測試IP檢測功能的方法

1. 使用 ngrok 進行外部測試

• 安裝 ngrok: npm install -g ngrok

• 啟動隧道: ngrok http 3000

• 使用 ngrok 提供的URL訪問你的應用

• 這樣就能測試真實的IP檢測功能

2. 部署到生產環境

• 部署到 Vercel、Netlify 或其他平台

• 在生產環境中,IP檢測會更準確

• 可以測試真實的IP白名單功能

3. 使用代理服務器

• 配置 Nginx 或 Apache 作為反向代理

• 確保正確設置 IP 轉發頭

• 這樣可以模擬生產環境的IP檢測

{/* 配置建議 */} 配置建議 根據不同環境的配置建議

本地開發環境

.env.local 中設置:

{`# 禁用IP白名單檢查
ENABLE_IP_WHITELIST=false

# 或者允許本地IP
ALLOWED_IPS=127.0.0.1,192.168.1.0/24`}
                

生產環境

在生產環境中設置:

{`# 啟用IP白名單
ENABLE_IP_WHITELIST=true

# 設置允許的IP地址
ALLOWED_IPS=你的真實IP地址,其他允許的IP`}
                
{/* 快速連結 */}
) }