Browse Source

feat: add CIDR support

pull/1/head
Dnomd343 3 years ago
parent
commit
736710f49c
  1. 31
      backend/getInfo.php
  2. 6
      index.html

31
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;
}
}
?>

6
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 @@
<td id="isp"></td>
</tr>
<tr>
<td>CIDR</td>
<td id="cidr"></td>
<td>Scope</td>
<td id="scope"></td>
</tr>
<tr>
<td>Detail</td>

Loading…
Cancel
Save