diff --git a/backend/getInfo.php b/backend/getInfo.php index d8d2466..9b9fbc1 100644 --- a/backend/getInfo.php +++ b/backend/getInfo.php @@ -28,20 +28,20 @@ function getIPInfo($ip) { $info['loc'] = $rawIspInfo['loc']; $info['isp'] = getIsp($rawIspInfo); } - $info['cidr'] = $detail['beginIP'] . ' - ' . $detail['endIP']; + $info['scope'] = tryCIDR($detail['beginIP'], $detail['endIP']); $info['detail'] = $detail['dataA'] . $detail['dataB']; if ($_GET['cli'] == "true") { // 使用命令行模式 - $cli = "IP: ".$info['ip'].PHP_EOL; - $cli .= "AS: ".$info['as'].PHP_EOL; - $cli .= "City: ".$info['city'].PHP_EOL; - $cli .= "Region: ".$info['region'].PHP_EOL; - $cli .= "Country: ".$info['country'].PHP_EOL; - $cli .= "Timezone: ".$info['timezone'].PHP_EOL; - $cli .= "Location: ".$info['loc'].PHP_EOL; - $cli .= "ISP: ".$info['isp'].PHP_EOL; - $cli .= "CIDR: ".$info['cidr'].PHP_EOL; - $cli .= "Detail: ".$info['detail'].PHP_EOL; + $cli = "IP: ".$info['ip'] . PHP_EOL; + $cli .= "AS: ".$info['as'] . PHP_EOL; + $cli .= "City: ".$info['city'] . PHP_EOL; + $cli .= "Region: ".$info['region'] . PHP_EOL; + $cli .= "Country: ".$info['country'] . PHP_EOL; + $cli .= "Timezone: ".$info['timezone'] . PHP_EOL; + $cli .= "Location: ".$info['loc'] . PHP_EOL; + $cli .= "ISP: ".$info['isp'] . PHP_EOL; + $cli .= "Scope: ".$info['scope'] . PHP_EOL; + $cli .= "Detail: ".$info['detail'] . PHP_EOL; return $cli; } @@ -113,4 +113,13 @@ function getAS($rawIspInfo) { // 提取AS信息 return trim($as['0']); } +function tryCIDR($beginIP, $endIP) { + $tmp = ip2long($endIP) - ip2long($beginIP) + 1; + if (pow(2, intval(log($tmp, 2))) == $tmp) { + return $beginIP . '/' . (32 - log($tmp, 2)); + } else { + return $beginIP . ' - ' . $endIP; + } +} + ?> diff --git a/index.html b/index.html index 61560e6..ab417b0 100644 --- a/index.html +++ b/index.html @@ -26,7 +26,7 @@ $("#timezone").text(data.timezone); $("#loc").text(data.loc); $("#isp").text(data.isp); - $("#cidr").text(data.cidr); + $("#scope").text(data.scope); $("#detail").text(data.detail); }); }); @@ -72,8 +72,8 @@