src/AppBundle/Common/ConvertIpToolkit.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace AppBundle\Common;
class ConvertIpToolkit
{
//https://www.ipip.net/product/ip.html
private static $ip = null;
private static $fp = null;
private static $offset = null;
private static $index = null;
public static function convertIps(array $array)
{
$result = array();
foreach ($array as $key => $value) {
$location = static::convertIp($value['ip']);
if ('N/A' == $location) {
$location = '未知区域';
}
$value['location'] = $location;
$result[$key] = $value;
}
return $result;
}
public static function convertIp($ip)
{
if (true === empty($ip)) {
return 'N/A';
}
$nip = gethostbyname($ip);
$ipdot = explode('.', $nip);
if ($ipdot[0] < 0 || $ipdot[0] > 255 || 4 !== count($ipdot)) {
return 'N/A';
}
if (null === self::$fp) {
self::init();
}
$nip2 = pack('N', ip2long($nip));
$tmp_offset = ((int) $ipdot[0] * 256 + (int) $ipdot[1]) * 4;
$start = unpack('Vlen', self::$index[$tmp_offset].self::$index[$tmp_offset + 1].self::$index[$tmp_offset + 2].self::$index[$tmp_offset + 3]);
$index_offset = $index_length = null;
$max_comp_len = self::$offset['len'] - 262144 - 4;
for ($start = $start['len'] * 9 + 262144; $start < $max_comp_len; $start += 9) {
if (self::$index[$start].self::$index[$start + 1].self::$index[$start + 2].self::$index[$start + 3] >= $nip2) {
$index_offset = unpack('Vlen', self::$index[$start + 4].self::$index[$start + 5].self::$index[$start + 6]."\x0");
$index_length = unpack('nlen', self::$index[$start + 7].self::$index[$start + 8]);
break;
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。