'use client' import { useState, useEffect } from 'react' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Separator } from '@/components/ui/separator' import { Alert, AlertDescription } from '@/components/ui/alert' import { Globe, Shield, MapPin, RefreshCw, AlertCircle, CheckCircle, Info, Lightbulb } 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 } location: any development: { message: string suggestions: string[] } | null } 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("無法獲取IP信息:", error) setError("無法獲取IP信息") } finally { setLoading(false) } } useEffect(() => { fetchIpInfo() }, []) if (loading) { return (
載入中...
) } if (error || !ipInfo) { return (
錯誤

{error || '無法獲取IP信息'}

) } return (

IP 檢測調試工具

查看詳細的IP檢測信息和調試數據

{/* 本地開發環境提示 */} {ipInfo.development && (
{ipInfo.development.message}
{ipInfo.development.suggestions.map((suggestion, index) => (
{suggestion}
))}
)} {/* 主要IP信息 */} IP 信息
檢測到的IP: {ipInfo.ip}
狀態: {ipInfo.isAllowed ? ( 允許 ) : ( 拒絕 )}
IP白名單: {ipInfo.enableIpWhitelist ? '已啟用' : '已停用'}
環境: {ipInfo.debug.environment}
{ipInfo.debug.isLocalDevelopment && ipInfo.debug.localIp && (
本機IP: {ipInfo.debug.localIp}
)}
{ipInfo.location && (
位置: {ipInfo.location.city}, {ipInfo.location.country} ({ipInfo.location.isp})
)}
{/* 所有找到的IP */} 所有檢測到的IP 系統檢測到的所有IP地址
{ipInfo.debug.allFoundIps.length > 0 ? ( ipInfo.debug.allFoundIps.map((ip, index) => ( {ip} {ip === ipInfo.ip && '(已選擇)'} )) ) : ( 未檢測到任何IP )}
{/* 允許的IP列表 */} {ipInfo.enableIpWhitelist && ( 允許的IP地址 當前配置的IP白名單
{ipInfo.allowedIps.length > 0 ? ( ipInfo.allowedIps.map((ip, index) => ( {ip} )) ) : ( 未配置IP白名單 )}
)} {/* 調試信息 */} 調試信息 所有可能的IP來源和請求頭信息

所有IP來源:

{Object.entries(ipInfo.debug.allIpSources).map(([key, value]) => (
{key}: {value || 'null'}
))}

請求信息:

Host: {ipInfo.debug.host || 'null'}
Referer: {ipInfo.debug.referer || 'null'}
User Agent: {ipInfo.debug.userAgent || 'null'}
時間戳: {new Date(ipInfo.timestamp).toLocaleString('zh-TW')}
{/* 地理位置信息 */} {ipInfo.location && ( 地理位置信息

位置信息

國家: {ipInfo.location.country} ({ipInfo.location.countryCode})
地區: {ipInfo.location.regionName}
城市: {ipInfo.location.city}
郵遞區號: {ipInfo.location.zip}
時區: {ipInfo.location.timezone}

網路信息

ISP: {ipInfo.location.isp}
組織: {ipInfo.location.org}
AS: {ipInfo.location.as}
行動網路: {ipInfo.location.mobile ? '是' : '否'}
代理: {ipInfo.location.proxy ? '是' : '否'}
主機服務: {ipInfo.location.hosting ? '是' : '否'}
)} {/* 操作按鈕 */}
) }