Total Complexity | 6 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
5 | class Util |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @var int |
||
10 | */ |
||
11 | public const IPv4_INT_MAX = 4294967295; |
||
12 | |||
13 | /** |
||
14 | * @param string $ip |
||
15 | * |
||
16 | * @return bool |
||
17 | */ |
||
18 | public static function isIPv6(string $ip): bool |
||
19 | { |
||
20 | return (bool)\inet_ntop($ip); |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @param string $ip |
||
25 | * |
||
26 | * @return bool |
||
27 | */ |
||
28 | public static function isIPv4(string $ip): bool |
||
29 | { |
||
30 | return (bool)\ip2long($ip); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param string $ip |
||
35 | * @return string |
||
36 | */ |
||
37 | public static function ip2long(string $ip): string |
||
38 | { |
||
39 | return \gmp_import(\inet_pton($ip)); |
||
|
|||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param string $long |
||
44 | * @param bool $forceIPv6 |
||
45 | * @return string |
||
46 | */ |
||
47 | public static function long2ip(string $long, bool $forceIPv6 = false): string |
||
64 | } |
||
65 | |||
66 | } |
||
67 |