【开源】开心狐IP AS号信息查询工具
易百益 - 网络资源分享平台,优质软件、程序、工具一站式获取

【开源】开心狐IP AS号信息查询工具

yibaiyi
2024-11-10 发布 /正在检测是否收录...

Screenshot_2024-11-10-16-58-21-797_com.microsoft.emmx.png

开心狐IP AS号信息查询工具
https://ip.kxfox.com 是一个实用的 IP 和 ASN 信息查询工具,支持查询全球 IP 地址的详细数据,如地理位置、运营商和自治系统信息。依托稳定的第三方接口,提供准确和实时的网络分析服务,适合进行网络故障排查和信息安全监测。其简单直观的界面方便用户操作,非常适合写博客时分享给那些需要快速查询网络信息的用户。

本地搭建后把里面 www.kxfox.com 这些域名改成自己的(否则无法查询成功)源代码如下:

index.html

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IP 和 ASN 信息查询 - 查询全球 IP 与 ASN 详情</title>
    <meta name="description" content="快速查询 IP 地址和 ASN 号的详细信息,包括国家、城市、ISP、ASN 持有者、资源块等内容,了解全球 IP 及网络资源信息。">
    <style>
        /* 重置样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: Arial, sans-serif;
        }
        body {
            background: linear-gradient(135deg, #4b6cb7, #182848);
            color: #f4f4f9;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }
        .container {
            max-width: 800px;
            width: 100%;
            background-color: #222831;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
            animation: fadeIn 1.5s ease;
        }
        h1 {
            font-size: 28px;
            margin-bottom: 20px;
            text-align: center;
            color: #f1f1f1;
            letter-spacing: 1px;
        }
        .input-group {
            display: flex;
            margin-bottom: 20px;
        }
        input[type="text"] {
            flex: 1;
            padding: 12px;
            border: none;
            border-radius: 6px 0 0 6px;
            outline: none;
            font-size: 16px;
            color: #333;
            transition: 0.3s;
        }
        input[type="text"]:focus {
            box-shadow: 0 0 10px rgba(255, 165, 0, 0.4);
        }
        button {
            padding: 12px 20px;
            background-color: #ff5722;
            border: none;
            border-radius: 0 6px 6px 0;
            color: #fff;
            font-size: 16px;
            cursor: pointer;
            transition: 0.3s;
        }
        button:hover {
            background-color: #ff7849;
        }
        .results-wrapper {
            display: flex;
            flex-direction: column;
            gap: 20px;
            margin-top: 20px;
        }
        .result-section {
            padding: 20px;
            background-color: #393e46;
            border-radius: 8px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
        }
        .result-section h2 {
            font-size: 22px;
            margin-bottom: 10px;
            color: #ff5722;
        }
        .info {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }
        .info p {
            flex: 1 1 48%;
            color: #eeeeee;
            padding: 8px 0;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        .info p span {
            font-weight: bold;
            color: #ffcc00;
        }
        .loading {
            font-weight: bold;
            color: #4caf50;
        }
        .error {
            font-weight: bold;
            color: #f44336;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        @media (max-width: 600px) {
            .result-section h2, h1 { font-size: 20px; }
            .input-group { flex-direction: column; }
            input[type="text"], button {
                width: 100%;
                border-radius: 6px;
                margin-top: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>IP 和 ASN 信息查询</h1>
        <div class="input-group">
            <input type="text" id="ip" placeholder="请输入 IP 地址">
            <button onclick="fetchInfo()">查询</button>
        </div>

        <div class="results-wrapper">
            <section class="result-section" id="ipResult">
                <h2>IP 信息</h2>
                <div class="info">
                    <p>请输入 IP 地址后点击“查询”以查看详细信息。</p>
                </div>
            </section>
            <section class="result-section" id="asnResult">
                <h2>ASN 信息</h2>
                <div class="info">
                    <p>查询 IP 信息时会自动加载 ASN 详细信息。</p>
                </div>
            </section>
        </div>
    </div>

    <script>
        function fetchInfo() {
            const ip = document.getElementById('ip').value.trim();
            const ipResultDiv = document.getElementById('ipResult').querySelector('.info');
            const asnResultDiv = document.getElementById('asnResult').querySelector('.info');

            ipResultDiv.innerHTML = '<p class="loading">查询中...</p>';
            asnResultDiv.innerHTML = '<p class="loading">加载中...</p>';

            if (!ip) {
                ipResultDiv.innerHTML = '<p class="error">请输入有效的 IP 地址</p>';
                asnResultDiv.innerHTML = '<p>查询 IP 信息时会自动加载 ASN 详细信息。</p>';
                return;
            }

            fetch(`ip_info.php?ip=${encodeURIComponent(ip)}`)
                .then(response => response.json())
                .then(data => {
                    if (data.error) {
                        ipResultDiv.innerHTML = `<p class="error">错误: ${data.error}</p>`;
                        asnResultDiv.innerHTML = '<p>查询 IP 信息时会自动加载 ASN 详细信息。</p>';
                    } else {
                        ipResultDiv.innerHTML = `
                            <p><span>IP地址:</span> ${data.ip}</p>
                            <p><span>国家:</span> ${data.country} (${data.countryCode})</p>
                            <p><span>地区:</span> ${data.region}</p>
                            <p><span>城市:</span> ${data.city}</p>
                            <p><span>ISP:</span> ${data.isp}</p>
                            <p><span>ASN:</span> ${data.asn}</p>
                            <p><span>经度:</span> ${data.lat}</p>
                            <p><span>纬度:</span> ${data.lon}</p>
                        `;
                        // 提取ASN中的数字并调用 fetchAsnInfo
                        const asnNumber = data.asn.replace(/[^\d]/g, '');
                        fetchAsnInfo(asnNumber);
                    }
                })
                .catch(error => {
                    ipResultDiv.innerHTML = `<p class="error">查询失败: ${error.message}</p>`;
                    asnResultDiv.innerHTML = '<p>查询 IP 信息时会自动加载 ASN 详细信息。</p>';
                });
        }

        function fetchAsnInfo(asn) {
            const asnResultDiv = document.getElementById('asnResult').querySelector('.info');
            asnResultDiv.innerHTML = '<p class="loading">加载中...</p>';

            fetch(`asn_info.php?asn=${encodeURIComponent(asn)}`)
                .then(response => response.json())
                .then(data => {
                    if (data.error) {
                        asnResultDiv.innerHTML = `<p class="error">错误: ${data.error}</p>`;
                    } else {
                        asnResultDiv.innerHTML = `
                            <p><span>ASN:</span> ${data.asn}</p>
                            <p><span>持有者:</span> ${data.holder}</p>
                            <p><span>资源范围:</span> ${data.block.resource}</p>
                            <p><span>描述:</span> ${data.block.desc}</p>
                            <p><span>分配名称:</span> ${data.block.name}</p>
                            <p><span>是否公告:</span> ${data.announced}</p>
                        `;
                    }
                })
                .catch(error => {
                    asnResultDiv.innerHTML = `<p class="error">查询失败: ${error.message}</p>`;
                });
        }
    </script>
</body>
</html>

asn_info.php

<?php
// 允许的来源页面 URL
$allowed_referrer = 'https://ip.kxfox.com';

// 检查请求来源是否为指定的页面
if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], $allowed_referrer) !== 0) {
    header('HTTP/1.1 403 Forbidden');
    echo json_encode(['error' => 'Unauthorized access - invalid referrer']);
    exit;
}

// 设置返回的响应头
header("Content-Type: application/json; charset=UTF-8");

// 验证 ASN 参数
if (!isset($_GET['asn']) || empty($_GET['asn'])) {
    echo json_encode(['error' => 'No ASN provided']);
    exit;
}

// 清理 ASN 参数,仅保留数字部分
$asn = preg_replace('/[^0-9]/', '', $_GET['asn']);
$api_url = "https://stat.ripe.net/data/as-overview/data.json?resource=AS$asn";

// 使用 cURL 请求 RIPE API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

// 检查 cURL 请求结果
if ($httpCode !== 200 || $response === false) {
    echo json_encode(['error' => 'Failed to fetch ASN information']);
    exit;
}

// 解析 JSON 数据
$data = json_decode($response, true);

// 验证 API 响应数据
if (isset($data['status']) && $data['status'] === "ok" && isset($data['data'])) {
    $asnData = $data['data'];
    $result = [
        'asn' => $asnData['resource'] ?? 'N/A',
        'holder' => $asnData['holder'] ?? 'N/A',
        'block' => [
            'resource' => $asnData['block']['resource'] ?? 'N/A',
            'desc' => $asnData['block']['desc'] ?? 'N/A',
            'name' => $asnData['block']['name'] ?? 'N/A'
        ],
        'announced' => isset($asnData['announced']) && $asnData['announced'] ? 'Yes' : 'No'
    ];
    echo json_encode($result);
} else {
    echo json_encode(['error' => 'ASN information not found']);
}
?>

ip_info.php

<?php
// 允许的来源页面 URL
$allowed_referrer = 'https://ip.kxfox.com';

// 检查请求来源是否为指定的页面
if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], $allowed_referrer) !== 0) {
    header('HTTP/1.1 403 Forbidden');
    echo json_encode(['error' => 'Unauthorized access - invalid referrer']);
    exit;
}

// 设置返回的响应头
header("Content-Type: application/json; charset=UTF-8");

// 验证 IP 参数
if (!isset($_GET['ip']) || empty($_GET['ip'])) {
    echo json_encode(['error' => 'No IP provided']);
    exit;
}

$ip = $_GET['ip'];
$api_url = "https://ipwhois.app/json/$ip";

// 获取 IP 信息
$response = file_get_contents($api_url);

if ($response === false) {
    echo json_encode(['error' => 'Failed to fetch IP information']);
    exit;
}

$data = json_decode($response, true);

// 检查 API 响应数据是否有效
if (isset($data['success']) && $data['success'] === false) {
    echo json_encode(['error' => 'IP information not found']);
} else {
    $result = [
        'ip' => $data['ip'] ?? 'N/A',
        'country' => $data['country'] ?? 'N/A',
        'countryCode' => $data['country_code'] ?? 'N/A',
        'region' => $data['region'] ?? 'N/A',
        'city' => $data['city'] ?? 'N/A',
        'isp' => $data['isp'] ?? 'N/A',
        'asn' => $data['asn'] ?? 'N/A',
        'lat' => $data['latitude'] ?? 'N/A',
        'lon' => $data['longitude'] ?? 'N/A'
    ];
    echo json_encode($result);
}
?>
© 版权声明
THE END
喜欢就支持一下吧
点赞 0 分享 收藏
评论 抢沙发
取消
SSL