如题,简单单页,响应式布局,手机电脑访问均可自适应;
使用的 ip-api.com 的免费 API;
预览图:
![图片[1]|【PHP】单页IP查询站点源码,可用于检测网络访问是否通畅|不死鸟资源网](https://www.busi.net/wp-content/uploads/2025/06/20250613191502158-image-1024x510.png)
保存为 index.php 从你站点即可
<?php
// functions.php
function get_ip_location($ip_address) {
$url = "http://ip-api.com/json/{$ip_address}?lang=zh-CN"; // 使用简体中文返回结果
$response = @file_get_contents($url); // 使用 @ 符号抑制错误信息
if ($response) {
$data = json_decode($response, true);
if ($data['status'] === 'success') {
return "{$data['country']} {$data['regionName']} {$data['city']}"; // 返回国家、地区和城市
}
}
return "未知归属地"; // 如果获取失败,则返回未知
}
// 获取IP地址
$local_ip = $_SERVER['REMOTE_ADDR']; // 用户的IP地址
$overseas_ip = '203.0.113.1'; // 示例没有被封的国外网站的IP地址
$google_ip = '172.217.0.0'; // 示例谷歌IP地址
// 获取归属地信息
$local_ip_location = get_ip_location($local_ip);
$overseas_ip_location = get_ip_location($overseas_ip);
$google_ip_location = get_ip_location($google_ip);
// 查询IP地址
$searched_ip_location = "";
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['ip_address'])) {
$searched_ip = htmlspecialchars(trim($_POST['ip_address']));
$searched_ip_location = get_ip_location($searched_ip);
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="https://ip.img.cd/favicon.png">
<title>IP地址查询</title>
<style>
a{text-decoration:none;color:#ff6a6a;}a:hover{text-decoration:none;color:#3b82f6;}body{margin:0; background-image: linear-gradient(to right, #fed6e3, #c0efec);background-color:;font-family:Arial,sans-serif;text-align:center;min-width:360px;height:auto;}.footer{position:fixed;left:0;bottom:0;width:100%;text-align:center;border-top:2px solid #f8f8f8;padding:10px 0;font-size:16px;height:26px;}.desktop{padding:10px 0;width:100%;background-color:rgba(255,255,255,0.75);font-size:24px;text-align:center;box-shadow:none;font-weight:;transition:box-shadow 0.3s ease;color:#ff6a6a;letter-spacing:2px;margin-bottom:20px;}.desktop:hover{box-shadow:0px 4px 10px rgba(59,130,246,0.5);color:#ff6a6a;}.desktop img{vertical-align:middle;margin-right:10px;}.ip-search{margin:25px auto;text-align:center;margin-bottom:25px;}.ip-search input[type="text"]{padding:12px;width:250px;border:1.3px solid #fff;border-radius:4px;font-size:16px;box-shadow:0 2px 5px rgba(0,0,0,0.1);outline:none;transition:border 0.3s,box-shadow 0.3s;background-color:rgba(255,255,255,0.1);}.ip-search input[type="text"]:focus{border-color:#3b82f6;box-shadow:0px 4px 10px rgba(59,130,246,0.5);}.ip-search button{padding:12px 15px;border:none;background-color:#3b82f6;color:white;border-radius:4px;font-size:16px;cursor:pointer;margin-left:10px;transition:background-color 0.3s,transform 0.3s;}.ip-search button:hover{background-color:#ff6a6a;transform:translateY(-2px);background-color:rgba(255,255,255,0.45);}.result{margin-top:20px;font-size:18px;color:#ff6a6a;}.ip-modules{display:flex;flex-wrap:wrap;justify-content:center;margin-top:15px;gap:40px;margin-bottom:60px;}.ip-module{width:350px;height:200px;padding:20px;background-color:rgba(255,255,255,0.2);border-radius:8px;box-shadow:0 2px 5px rgba(0,0,0,0.1);font-size:18px;color:#333;text-align:center;box-sizing:border-box;background-color:rgba(255,255,255,0.75);}.module-title{font-weight:bold;margin-bottom:10px;color:#3b82f6;padding:10px;border-radius:5px;}.module-title:hover{color:#ff6a6a;}</style>
</head>
<body>
<div class="desktop">
<img height="30" src="https://ip.img.cd/favicon.ico" alt="ximi "><!---->
<a href="https://ip.img.cd/" alt="IP查询 ip.img.cd">希米IP地址查询</a>
</div>
<div class="ip-search">
<form method="POST">
<input type="text" name="ip_address" placeholder="输入IP地址" required>
<button type="submit">查询</button>
</form>
<div class="result">
<?php
if ($searched_ip_location) {
echo "IP地址:<strong>{$searched_ip}</strong> 归属地是:<strong>{$searched_ip_location}</strong>";
}
?>
</div>
</div>
<div class="ip-modules">
<div class="ip-module">
<div class="module-title">这是您访问国内网站所使用的IP</div>
<iframe src="https://www.ximi.me/usr/tool/ip.php" width="100%" height="80" scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe>
</div>
<div class="ip-module">
<div class="module-title">这是您访问国外网站所使用的IP</div>
<iframe src="https://ip.img.cd/ip.php" width="100%" height="80" scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe>
</div>
<div class="ip-module">
<div class="module-title">这是您访问YouTube的IP</div>
<iframe src="https://ip.img.cd/ip-2.php" width="100%" height="80" scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe>
</div>
</div>
<script src="https://sing.ge/read/Read_address.js" defer></script>
<footer class="footer">
<div>
© 2024 <a href="https://www.ximi.me" target="_blank" rel="noopener noreferrer">ximi </a> 版权所有 <a href="https://sing.ge/index.php?url=ip.img.cd" target="_blank" title="站点统计" rel="noopener noreferrer">统计</a>
</div>
</footer>
</body>
</html>
本站资源均为作者提供和网友推荐收集整理而来,仅供学习和研究使用,请在下载后24小时内删除,谢谢合作!
THE END