"use client" import { useEffect, useState } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { RefreshCw, Shield, AlertTriangle, CheckCircle, Info, Cloud, Server } from "lucide-react" interface DiagnosticData { timestamp: string environment: string url: string ipAnalysis: { xForwardedFor: string | null xRealIp: string | null xClientIp: string | null cfConnectingIp: string | null forwarded: string | null xOriginalForwardedFor: string | null analysis: { hasCloudflare: boolean hasXForwardedFor: boolean hasXRealIp: boolean hasForwarded: boolean recommendedIpSource: string recommendedIp: string } } isCloudflare: { hasCfConnectingIp: boolean hasCfRay: boolean hasCfVisitor: boolean hasCfIpCountry: boolean cfRay: string | null cfCountry: string | null cfVisitor: string | null } proxyInfo: { hasNginxProxy: boolean has1Panel: boolean nginxProxyIp: string | null panelClientIp: string | null } ipChain: { xForwardedForChain: string[] recommendedClientIp: string } ipHeaders: Record otherHeaders: Record allHeaders: Record recommendations: { primaryIpSource: string primaryIp: string isCloudflareSetup: boolean isProxySetup: boolean suggestedConfig: string[] } } export default function IpDiagnosticPage() { const [diagnosticData, setDiagnosticData] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const fetchDiagnosticData = async () => { setLoading(true) setError(null) try { const response = await fetch('/api/ip-diagnostic') if (!response.ok) { throw new Error('無法獲取診斷數據') } const data = await response.json() setDiagnosticData(data) } catch (error) { console.error("無法獲取診斷數據:", error) setError("無法獲取診斷數據") } finally { setLoading(false) } } useEffect(() => { fetchDiagnosticData() }, []) if (loading) { return (
載入診斷數據中...
) } if (error || !diagnosticData) { return (
診斷失敗

{error}

) } return (

IP 診斷工具

{/* 環境檢測結果 */} 環境檢測結果
Cloudflare: {diagnosticData.isCloudflare.hasCfConnectingIp ? "檢測到" : "未檢測到"}
代理服務器: {diagnosticData.proxyInfo.hasNginxProxy || diagnosticData.proxyInfo.has1Panel ? "檢測到" : "未檢測到"}
IP來源: {diagnosticData.recommendations.primaryIpSource}
{/* 推薦的IP */}

推薦使用的客戶端IP

{diagnosticData.recommendations.primaryIp}

來源: {diagnosticData.recommendations.primaryIpSource}

{/* Cloudflare 信息 */} {diagnosticData.isCloudflare.hasCfConnectingIp && ( Cloudflare 信息

{diagnosticData.ipAnalysis.cfConnectingIp || 'null'}

{diagnosticData.isCloudflare.cfRay || 'null'}

{diagnosticData.isCloudflare.cfCountry || 'null'}

{diagnosticData.isCloudflare.cfVisitor || 'null'}

)} {/* 代理信息 */} {(diagnosticData.proxyInfo.hasNginxProxy || diagnosticData.proxyInfo.has1Panel) && ( 代理服務器信息 {diagnosticData.proxyInfo.hasNginxProxy && (

{diagnosticData.proxyInfo.nginxProxyIp || 'null'}

)} {diagnosticData.proxyInfo.has1Panel && (

{diagnosticData.proxyInfo.panelClientIp || 'null'}

)}
)} {/* IP鏈分析 */} IP 鏈分析
{diagnosticData.ipChain.xForwardedForChain.length > 0 ? (
{diagnosticData.ipChain.xForwardedForChain.map((ip, index) => (
{index === 0 ? "客戶端" : `代理${index}`} {ip}
))}
) : (

無 X-Forwarded-For 頭部

)}
{/* 所有IP相關頭部 */} 所有 IP 相關頭部
{Object.entries(diagnosticData.ipHeaders).map(([key, value]) => (
{key}: {value || 'null'}
))}
{/* 配置建議 */} 配置建議
{diagnosticData.recommendations.suggestedConfig.map((suggestion, index) => (

{suggestion}

))}
{/* 完整頭部列表 */} 完整 HTTP 頭部列表
{Object.entries(diagnosticData.allHeaders).map(([key, value]) => (
{key}: {value}
))}
{/* 使用說明 */} 使用說明

1. 查看上面的診斷結果,確認你的環境類型(Cloudflare、代理、直接連接)

2. 檢查「推薦使用的客戶端IP」是否為你的真實IP (114.33.18.13)

3. 如果不是,請將診斷結果截圖發給我,我會根據實際的頭部信息調整IP檢測邏輯

4. 特別注意 X-Forwarded-For 鏈和 Cloudflare 相關頭部

) }