'中国', 'United States' => '美国', 'Japan' => '日本', 'South Korea' => '韩国', 'Singapore' => '新加坡', 'Hong Kong' => '香港', 'Taiwan' => '台湾', 'Macao' => '澳门', 'United Kingdom' => '英国', 'Germany' => '德国', 'France' => '法国', 'Canada' => '加拿大', 'Australia' => '澳大利亚', 'Russia' => '俄罗斯', 'India' => '印度', 'Thailand' => '泰国', 'Malaysia' => '马来西亚', 'Indonesia' => '印度尼西亚', 'Philippines' => '菲律宾', 'Vietnam' => '越南', // 地区/省份 'Beijing' => '北京', 'Shanghai' => '上海', 'Guangdong' => '广东', 'Zhejiang' => '浙江', 'Jiangsu' => '江苏', 'Shandong' => '山东', 'Henan' => '河南', 'Sichuan' => '四川', 'Hubei' => '湖北', 'Hunan' => '湖南', 'Fujian' => '福建', 'Anhui' => '安徽', 'Liaoning' => '辽宁', 'Shaanxi' => '陕西', 'Chongqing' => '重庆', 'Tianjin' => '天津', // 城市 'Shenzhen' => '深圳', 'Guangzhou' => '广州', 'Hangzhou' => '杭州', 'Nanjing' => '南京', 'Wuhan' => '武汉', 'Chengdu' => '成都', 'Xian' => '西安', 'Suzhou' => '苏州', 'Qingdao' => '青岛', 'Dalian' => '大连', 'Xiamen' => '厦门', 'Ningbo' => '宁波', 'Changsha' => '长沙', 'Zhengzhou' => '郑州', 'Jinan' => '济南', 'Harbin' => '哈尔滨', 'Changchun' => '长春', 'Shenyang' => '沈阳', 'Kunming' => '昆明', 'Nanning' => '南宁', 'Taiyuan' => '太原', 'Shijiazhuang' => '石家庄', 'Lanzhou' => '兰州', 'Urumqi' => '乌鲁木齐', 'Lhasa' => '拉萨', 'Hohhot' => '呼和浩特', 'Yinchuan' => '银川', 'Xining' => '西宁', 'Haikou' => '海口', 'Nanchang' => '南昌', 'Hefei' => '合肥', 'Fuzhou' => '福州', 'Guiyang' => '贵阳' ]; return isset($translations[$text]) ? $translations[$text] : $text; } /** * 判断IP地址类型的函数 */ function getNetworkType($ip) { if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { return "公网IP"; } else { return "内部网络"; } } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { return "IPv6网络"; } else { return "未知网络"; } } /** * 获取IP地址的地理位置信息 * @param string $ip IP地址 * @return string 地理位置信息 */ function getLocationInfo($ip) { // 检查是否为内网IP if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) { return '本地网络, 内网IP'; } // 优先使用百度IP查询API $baiduResult = getBaiduIPLocation($ip); if ($baiduResult && is_array($baiduResult) && !empty($baiduResult['location'])) { return $baiduResult; } // 如果百度API失败,使用其他API $location = getIPLocation($ip); return $location ? $location : '公网IP, 位置检测中...'; } /** * 通过百度API获取IP地理位置信息 * @param string $ip IP地址 * @return array|false 地理位置信息数组或false */ function getBaiduIPLocation($ip) { $url = "http://opendata.baidu.com/api.php?query={$ip}&co=&resource_id=6006&oe=utf8"; // 设置超时时间为3秒 $context = stream_context_create([ 'http' => [ 'timeout' => 3, 'user_agent' => 'Mozilla/5.0 (compatible; IP Location Checker)', 'method' => 'GET' ] ]); $response = @file_get_contents($url, false, $context); if ($response === false) { return false; } $data = json_decode($response, true); if (!$data || !isset($data['data']) || empty($data['data'])) { return false; } $ipData = $data['data'][0]; // 解析百度API返回的数据,确保中文显示 $country = '中国'; $region = '未知地区'; $city = '未知城市'; $isp = '未知运营商'; $coords = null; $timezone = null; // 解析location字段 if (isset($ipData['location'])) { $locationParts = explode(' ', $ipData['location']); if (count($locationParts) >= 2) { $region = $locationParts[0]; $city = $locationParts[1]; } } // 解析坐标信息 if (isset($ipData['lat']) && isset($ipData['lng'])) { $coords = $ipData['lat'] . ', ' . $ipData['lng']; } // 解析运营商信息 if (isset($ipData['isp'])) { $isp = $ipData['isp']; } // 解析时区信息 if (isset($ipData['timezone'])) { $timezone = $ipData['timezone']; } // 构建详细的位置信息(中文格式) $location = $country; if ($region !== '未知地区') $location .= ' ' . $region; if ($city !== '未知城市') $location .= ' ' . $city; if ($coords) $location .= ' [坐标: ' . $coords . ']'; if ($isp !== '未知运营商') $location .= ' - ' . $isp; if ($timezone) $location .= ' | 时区: ' . $timezone; $location .= ' [百度IP库]'; return array( 'country' => $country, 'region' => $region, 'city' => $city, 'isp' => $isp, 'location' => $location, 'coords' => $coords, 'timezone' => $timezone ); } /** * 通过API获取IP地理位置信息 - 多源验证版 * @param string $ip IP地址 * @return string|false 地理位置信息或false */ function getIPLocation($ip) { // 多个API源,用于交叉验证 $apis = [ "http://ip-api.com/json/{$ip}?lang=zh-CN&fields=status,message,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,timezone,isp,org,as,query", "https://ipapi.co/{$ip}/json/", "https://ipinfo.io/{$ip}/json", "http://www.geoplugin.net/json.gp?ip={$ip}", "https://api.ipgeolocation.io/ipgeo?apiKey=free&ip={$ip}&lang=zh", "https://ipwhois.app/json/{$ip}?lang=zh", "https://api.ip2location.com/v2/?ip={$ip}&key=demo&package=WS24", "http://ip.taobao.com/outGetIpInfo?ip={$ip}&accessKey=alibaba-inc" ]; $results = []; $validResults = []; // 收集多个API的结果 foreach ($apis as $api) { $result = getLocationFromAPI($api, $ip); if ($result) { $results[] = $result; // 解析城市信息用于验证 if (preg_match('/([^,]+),\s*([^,]+),\s*([^,\[\(]+)/', $result, $matches)) { $validResults[] = [ 'country' => trim($matches[1]), 'region' => trim($matches[2]), 'city' => trim($matches[3]), 'full' => $result ]; } } } if (empty($validResults)) { return false; } // 如果只有一个结果,直接返回 if (count($validResults) == 1) { return $validResults[0]['full']; } // 多源验证:找出最常见的城市 $cityCount = []; foreach ($validResults as $result) { $cityKey = $result['region'] . ',' . $result['city']; if (!isset($cityCount[$cityKey])) { $cityCount[$cityKey] = ['count' => 0, 'result' => $result]; } $cityCount[$cityKey]['count']++; } // 按出现次数排序 uasort($cityCount, function($a, $b) { return $b['count'] - $a['count']; }); $mostCommon = reset($cityCount); // 如果最常见的结果出现次数大于1,或者只有一种结果,返回它 if ($mostCommon['count'] > 1 || count($cityCount) == 1) { return $mostCommon['result']['full']; } // 否则返回第一个结果,但添加验证提示 return $validResults[0]['full'] . ' [多源验证中]'; } /** * 从指定API获取位置信息 * @param string $url API URL * @param string $ip IP地址 * @return string|false 位置信息或false */ function getLocationFromAPI($url, $ip) { // 设置超时时间为3秒 $context = stream_context_create([ 'http' => [ 'timeout' => 3, 'user_agent' => 'Mozilla/5.0 (compatible; IP Location Checker)' ] ]); $response = @file_get_contents($url, false, $context); if ($response === false) { return false; } $data = json_decode($response, true); if (!$data) { return false; } // 根据不同API格式解析数据,提供更详细的位置信息(中文格式) if (strpos($url, 'ip-api.com') !== false) { if (isset($data['status']) && $data['status'] === 'success') { $country = isset($data['country']) ? translateToChineseLocation($data['country']) : '未知国家'; $region = isset($data['regionName']) ? translateToChineseLocation($data['regionName']) : '未知地区'; $city = isset($data['city']) ? translateToChineseLocation($data['city']) : '未知城市'; $district = isset($data['district']) ? translateToChineseLocation($data['district']) : ''; $zip = isset($data['zip']) ? $data['zip'] : ''; $isp = isset($data['isp']) ? $data['isp'] : (isset($data['org']) ? $data['org'] : '未知运营商'); $timezone = isset($data['timezone']) ? $data['timezone'] : ''; $lat = isset($data['lat']) ? $data['lat'] : ''; $lon = isset($data['lon']) ? $data['lon'] : ''; if ($country && $city) { $location = "{$country} {$region} {$city}"; if ($district) $location .= " {$district}"; if ($zip) $location .= " ({$zip})"; if ($lat && $lon) $location .= " [坐标: {$lat}, {$lon}]"; $location .= " - {$isp}"; if ($timezone) $location .= " | 时区: {$timezone}"; return $location; } } } elseif (strpos($url, 'ipapi.co') !== false) { if (isset($data['country_name']) && isset($data['city'])) { $country = translateToChineseLocation($data['country_name']); $region = isset($data['region']) ? translateToChineseLocation($data['region']) : '未知地区'; $city = translateToChineseLocation($data['city']); $postal = isset($data['postal']) ? $data['postal'] : ''; $isp = isset($data['org']) ? $data['org'] : '未知运营商'; $timezone = isset($data['timezone']) ? $data['timezone'] : ''; $lat = isset($data['latitude']) ? $data['latitude'] : ''; $lon = isset($data['longitude']) ? $data['longitude'] : ''; $location = "{$country} {$region} {$city}"; if ($postal) $location .= " ({$postal})"; if ($lat && $lon) $location .= " [坐标: {$lat}, {$lon}]"; $location .= " - {$isp}"; if ($timezone) $location .= " | 时区: {$timezone}"; return $location; } } elseif (strpos($url, 'ipinfo.io') !== false) { if (isset($data['country']) && isset($data['city'])) { $country = translateToChineseLocation($data['country']); $region = isset($data['region']) ? translateToChineseLocation($data['region']) : ''; $city = translateToChineseLocation($data['city']); $postal = isset($data['postal']) ? $data['postal'] : ''; $isp = isset($data['org']) ? $data['org'] : '未知运营商'; $timezone = isset($data['timezone']) ? $data['timezone'] : ''; $loc = isset($data['loc']) ? $data['loc'] : ''; $location = "{$country} {$region} {$city}"; if ($postal) $location .= " ({$postal})"; if ($loc) $location .= " [坐标: {$loc}]"; $location .= " - {$isp}"; if ($timezone) $location .= " | 时区: {$timezone}"; return $location; } } elseif (strpos($url, 'geoplugin.net') !== false) { if (isset($data['geoplugin_status']) && $data['geoplugin_status'] == 200) { $country = isset($data['geoplugin_countryName']) ? translateToChineseLocation($data['geoplugin_countryName']) : ''; $region = isset($data['geoplugin_regionName']) ? translateToChineseLocation($data['geoplugin_regionName']) : ''; $city = isset($data['geoplugin_city']) ? translateToChineseLocation($data['geoplugin_city']) : ''; $lat = isset($data['geoplugin_latitude']) ? $data['geoplugin_latitude'] : ''; $lon = isset($data['geoplugin_longitude']) ? $data['geoplugin_longitude'] : ''; $timezone = isset($data['geoplugin_timezone']) ? $data['geoplugin_timezone'] : ''; if ($country && $city) { $location = "{$country} {$region} {$city}"; if ($lat && $lon) $location .= " [坐标: {$lat}, {$lon}]"; if ($timezone) $location .= " | 时区: {$timezone}"; return $location; } } } elseif (strpos($url, 'ipgeolocation.io') !== false) { if (isset($data['country_name']) && isset($data['city'])) { $country = translateToChineseLocation($data['country_name']); $state = isset($data['state_prov']) ? translateToChineseLocation($data['state_prov']) : ''; $city = translateToChineseLocation($data['city']); $district = isset($data['district']) ? translateToChineseLocation($data['district']) : ''; $zipcode = isset($data['zipcode']) ? $data['zipcode'] : ''; $isp = isset($data['isp']) ? $data['isp'] : '未知运营商'; $timezone = isset($data['time_zone']['name']) ? $data['time_zone']['name'] : ''; $lat = isset($data['latitude']) ? $data['latitude'] : ''; $lon = isset($data['longitude']) ? $data['longitude'] : ''; $location = "{$country} {$state} {$city}"; if ($district) $location .= " {$district}"; if ($zipcode) $location .= " ({$zipcode})"; if ($lat && $lon) $location .= " [坐标: {$lat}, {$lon}]"; $location .= " - {$isp}"; if ($timezone) $location .= " | 时区: {$timezone}"; return $location; } } elseif (strpos($url, 'ipwhois.app') !== false) { if (isset($data['success']) && $data['success'] && isset($data['country']) && isset($data['city'])) { $country = translateToChineseLocation($data['country']); $region = isset($data['region']) ? translateToChineseLocation($data['region']) : ''; $city = translateToChineseLocation($data['city']); $isp = isset($data['isp']) ? $data['isp'] : '未知运营商'; $timezone = isset($data['timezone']) ? $data['timezone'] : ''; $lat = isset($data['latitude']) ? $data['latitude'] : ''; $lon = isset($data['longitude']) ? $data['longitude'] : ''; $location = "{$country} {$region} {$city}"; if ($lat && $lon) $location .= " [坐标: {$lat}, {$lon}]"; $location .= " - {$isp}"; if ($timezone) $location .= " | 时区: {$timezone}"; return $location; } } elseif (strpos($url, 'ip2location.com') !== false) { if (isset($data['country_name']) && isset($data['city_name'])) { $country = translateToChineseLocation($data['country_name']); $region = isset($data['region_name']) ? translateToChineseLocation($data['region_name']) : ''; $city = translateToChineseLocation($data['city_name']); $isp = isset($data['isp']) ? $data['isp'] : '未知运营商'; $timezone = isset($data['time_zone']) ? $data['time_zone'] : ''; $lat = isset($data['latitude']) ? $data['latitude'] : ''; $lon = isset($data['longitude']) ? $data['longitude'] : ''; $location = "{$country} {$region} {$city}"; if ($lat && $lon) $location .= " [坐标: {$lat}, {$lon}]"; $location .= " - {$isp}"; if ($timezone) $location .= " | 时区: {$timezone}"; return $location; } } elseif (strpos($url, 'ip.taobao.com') !== false) { if (isset($data['code']) && $data['code'] == 0 && isset($data['data'])) { $ipData = $data['data']; $country = isset($ipData['country']) ? translateToChineseLocation($ipData['country']) : ''; $region = isset($ipData['region']) ? translateToChineseLocation($ipData['region']) : ''; $city = isset($ipData['city']) ? translateToChineseLocation($ipData['city']) : ''; $county = isset($ipData['county']) ? translateToChineseLocation($ipData['county']) : ''; $isp = isset($ipData['isp']) ? $ipData['isp'] : '未知运营商'; if ($country && $city) { $location = "{$country} {$region} {$city}"; if ($county) $location .= " {$county}"; $location .= " - {$isp} [淘宝IP库]"; return $location; } } } return false; } /** * 获取威胁级别的函数 */ function getThreatLevel($ip) { // 这里可以添加更复杂的威胁检测逻辑 // 比如检查IP黑名单、地理位置等 $networkType = getNetworkType($ip); if ($networkType === "内部网络") { return "低风险"; } elseif ($networkType === "公网IP") { return "中等风险"; } else { return "未知风险"; } } // 获取访问者真实IP $clientIP = getRealIpAddr(); $networkType = getNetworkType($clientIP); $threatLevel = getThreatLevel($clientIP); $locationInfo = getLocationInfo($clientIP); // 获取用户代理信息 $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '未知'; // 获取访问时间 $accessTime = date('Y-m-d H:i:s'); ?> 高级安全防护系统 | 实时监控中

高级安全防护系统

实时威胁分析与入侵防御
检测到的访问来源
网络类型
地理位置
威胁级别
当前访问时间
--:--:--
----年--月--日
安全警报:检测到异常访问行为 - 已启动7级安全协议
系统深度扫描进度
65%
防护等级
7/10
企业级防护
系统锁定
100%
关键区域已隔离
威胁拦截
42
实时阻止攻击
警告: 所有访问行为正在被记录与分析