Browse Source

update: database of China city, optimize IP data

master
Dnomd343 3 years ago
parent
commit
442409f87d
  1. BIN
      backend/ChinaCity.db
  2. BIN
      backend/cityCN.db
  3. 6
      backend/cityCN.php
  4. 50
      backend/queryInfo.php

BIN
backend/ChinaCity.db

Binary file not shown.

BIN
backend/cityCN.db

Binary file not shown.

6
backend/city.php → backend/cityCN.php

@ -1,6 +1,6 @@
<?php
// 数据来源:ChinaCity.db
// 数据来源:cityCN.db
// 请求方式:getLoc($region, $city)
// 返回格式:
// {
@ -12,7 +12,7 @@
class cityDB extends SQLite3 {
function __construct() {
$this->open('ChinaCity.db'); // 中国省市经纬度数据库
$this->open('cityCN.db'); // 中国省市经纬度数据库
}
}
@ -26,6 +26,8 @@ function getLoc($region, $city) { // 根据省份/城市信息查询经纬度
$query_str='SELECT * FROM main WHERE level1="'.$region.'" AND level2="-";'; // 尝试仅查询省份数据
$raw = $db->query($query_str)->fetchArray(SQLITE3_ASSOC);
if (!$raw) { // 省份错误,返回北京经纬度
$data['region'] = '北京';
$data['city'] = '北京';
$data['lat'] = '39.91';
$data['lon'] = '116.73';
return $data;

50
backend/queryInfo.php

@ -4,7 +4,7 @@ include("country.php");
include("qqwry.php");
include("ipinfo.php");
include("ipip.php");
include("city.php");
include("cityCN.php");
function getIPInfo($ip) {
$specialInfo = checkSpecial($ip); // 检查是否为特殊IP段
@ -40,21 +40,51 @@ function getIPInfo($ip) {
if ($addr[0] == '中国' || $detail['country'] == '中国') {
$info['country'] = 'CN - China(中国)';
$info['timezone'] = 'Asia/Shanghai';
$flagErr = false;
if ($addr[1] == '' || $addr[2] == '') {
if ($detail['region'] != '' && $detail['city'] != '') {
$addr[1] = $detail['region']; // 修正IPIP.net数据
$addr[2] = $detail['city'];
} else {
$flagErr = true; // 国内数据不全
if ($detail['region'] == '台湾') { // 修正台湾数据带 "市" 或 "县" 的情况
if (mb_substr($detail['city'], -1) == '市' || mb_substr($detail['city'], -1) == '县') {
$detail['city'] = mb_substr($detail['city'], 0, mb_strlen($detail['city']) - 1);
}
}
if (!$flagErr) { // 国内数据可用
$cityLoc = getLoc($addr[1], $addr[2]); // 获取城市经纬度
if ($detail['region'] == '' && $detail['city'] == '') { // 纯真库解析不出数据
if ($addr[1] != '' || $addr[2] != '') { // IPIP数据不同时为空
$detail['region'] = $addr[1];
$detail['city'] = $addr[2];
}
} else if ($detail['region'] == '' || $detail['city'] == '') { // 纯真库存在空数据
if ($addr[1] != '' && $addr[2] != '') { // IPIP数据完整
$detail['region'] = $addr[1]; // 修正纯真数据
$detail['city'] = $addr[2];
}
}
if ($detail['region'] != '' || $detail['city'] != '') { // 修正后数据不同时为空
$cityLoc = getLoc($detail['region'], $detail['city']); // 获取城市经纬度
$info['region'] = $cityLoc['region'];
$info['city'] = $cityLoc['city'];
$info['loc'] = $cityLoc['lat'] . ',' . $cityLoc['lon'];
}
if ($detail['isp'] == '教育网') { // 载入纯真库分析出的ISP数据
$info['isp'] = 'China Education and Research Network';
} else if ($detail['isp'] == '电信') {
$info['isp'] = 'China Telecom';
} else if ($detail['isp'] == '联通') {
$info['isp'] = 'China Unicom Limited';
} else if ($detail['isp'] == '移动') {
$info['isp'] = 'China Mobile Communications Corporation';
} else if ($detail['isp'] == '铁通') {
$info['isp'] = 'China Tietong Telecom';
} else if ($detail['isp'] == '广电网') {
$info['isp'] = 'Shaanxi Broadcast & TV Network Intermediary';
} else if ($detail['isp'] == '鹏博士') {
$info['isp'] = 'Chengdu Dr.Peng Technology';
} else if ($detail['isp'] == '长城') {
$info['isp'] = 'Great Wall Broadband Network Service';
} else if ($detail['isp'] == '中华电信') {
$info['isp'] = 'ChungHwa Telecom';
} else if ($detail['isp'] == '亚太电信') {
$info['isp'] = 'Asia Pacific Telecom';
} else if ($detail['isp'] == '远传电信') {
$info['isp'] = 'Far EasTone Telecommunications';
}
}
if (filter_var($ip, \FILTER_VALIDATE_IP,\FILTER_FLAG_IPV4)) { // 录入纯真库数据
$info['scope'] = tryCIDR($detail['beginIP'], $detail['endIP']);

Loading…
Cancel
Save