mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-13 08:59:34 +03:00
feat: custom output text format
This commit is contained in:
@@ -155,4 +155,23 @@ class IP4Helper {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* преобразование короткой маски IPv4 в полную
|
||||
* @param string $mask
|
||||
* @return string
|
||||
*/
|
||||
public static function formatShortIpMask(string $mask): string {
|
||||
if ($mask == '') {
|
||||
$mask = '32';
|
||||
}
|
||||
$binaryMask = str_repeat('1', (int) $mask) . str_repeat('0', 32 - $mask);
|
||||
$octets = [];
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$octets[] = bindec(substr($binaryMask, $i * 8, 8));
|
||||
}
|
||||
|
||||
return implode('.', $octets);
|
||||
}
|
||||
}
|
||||
|
@@ -201,4 +201,24 @@ class IP6Helper {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* преобразование короткой маски IPv6 в полную
|
||||
* @param string $mask
|
||||
* @return string
|
||||
*/
|
||||
public static function formatShortIpMask(string $mask): string {
|
||||
if ($mask === '') {
|
||||
$mask = '128';
|
||||
}
|
||||
|
||||
$binaryMask = str_repeat('1', (int) $mask) . str_repeat('0', 128 - $mask);
|
||||
$hextets = [];
|
||||
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$hextets[] = dechex(bindec(substr($binaryMask, $i * 16, 16)));
|
||||
}
|
||||
|
||||
return implode(':', $hextets);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user