'use client' import { useState, useEffect } from 'react' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Alert, AlertDescription } from '@/components/ui/alert' import { Button } from '@/components/ui/button' import { Globe, Info, AlertCircle, CheckCircle, RefreshCw } from 'lucide-react' interface IpDebugInfo { ip: string isAllowed: boolean enableIpWhitelist: boolean allowedIps: string[] timestamp: string debug: { allIpSources: Record allFoundIps: string[] isLocalDevelopment: boolean localIp: string | null environment: string host: string | null referer: string | null userAgent: string | null originalDetectedIp: string finalDetectedIp: string } location: any development: any } export default function IpDebugPage() { const [ipInfo, setIpInfo] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const fetchIpInfo = async () => { setLoading(true) setError(null) try { const response = await fetch('/api/ip') if (!response.ok) { throw new Error('無法獲取IP信息') } const data = await response.json() setIpInfo(data) } catch (error) { console.error('Error fetching IP info:', error) setError('無法獲取IP信息') } finally { setLoading(false) } } useEffect(() => { fetchIpInfo() }, []) if (loading) { return (

載入中...

) } if (error || !ipInfo) { return (
{error}
) } return (

IP 調試信息

詳細的IP檢測和調試信息

{/* 主要IP信息 */} 檢測到的IP地址 系統檢測到的主要IP地址信息

最終檢測到的IP

{ipInfo.ip}

原始檢測到的IP

{ipInfo.debug.originalDetectedIp}

IP白名單狀態

{ipInfo.isAllowed ? '允許' : '拒絕'}

白名單功能

{ipInfo.enableIpWhitelist ? '已啟用' : '已禁用'}

環境

{ipInfo.debug.environment}
{/* 所有找到的IP */} 所有檢測到的IP地址 從各種來源檢測到的所有IP地址
{ipInfo.debug.allFoundIps.length > 0 ? ( ipInfo.debug.allFoundIps.map((ip, index) => (
{ip} {ip === ipInfo.ip && ( 最終選擇 )}
)) ) : (

沒有檢測到任何IP地址

)}
{/* IP來源詳細信息 */} IP來源詳細信息 各種HTTP頭和連接信息中的IP地址
{Object.entries(ipInfo.debug.allIpSources).map(([source, value]) => (
{source}: {value || '未設置'}
))}
{/* 本地開發環境信息 */} {ipInfo.development && (
{ipInfo.development.message}
{ipInfo.development.suggestions.map((suggestion, index) => (
• {suggestion}
))}
)} {/* 地理位置信息 */} {ipInfo.location && ( 地理位置信息 IP地址的地理位置信息
              {JSON.stringify(ipInfo.location, null, 2)}
            
)} {/* 其他調試信息 */} 其他調試信息 額外的調試和環境信息

主機

{ipInfo.debug.host || '未設置'}

引用來源

{ipInfo.debug.referer || '未設置'}

用戶代理

{ipInfo.debug.userAgent || '未設置'}

時間戳

{ipInfo.timestamp}

{/* 操作按鈕 */}
) }