| Total Complexity | 6 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 54.55% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class Ip |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * 判断是否为一个合法的IP地址 |
||
| 12 | * |
||
| 13 | * @param string $ip 需要判断的字符; |
||
| 14 | * |
||
| 15 | * @return bool |
||
| 16 | */ |
||
| 17 | 4 | public static function isIp($ip) |
|
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * 判断是否是ipv4. |
||
| 24 | * |
||
| 25 | * @param string $ip |
||
| 26 | * |
||
| 27 | * @return bool |
||
| 28 | */ |
||
| 29 | 4 | public static function isIp4($ip) |
|
| 30 | { |
||
| 31 | 4 | return false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); |
|
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * 判断是否是ipv6. |
||
| 36 | * |
||
| 37 | * @param string $ip |
||
| 38 | * |
||
| 39 | * @return bool |
||
| 40 | */ |
||
| 41 | 4 | public static function isIp6($ip) |
|
| 42 | { |
||
| 43 | 4 | return false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * 判断是否是内网ip. |
||
| 48 | * |
||
| 49 | * @param string $ip |
||
| 50 | * |
||
| 51 | * @return bool |
||
| 52 | */ |
||
| 53 | public static function isPrivateIp($ip) |
||
| 54 | { |
||
| 55 | return false === filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) |
||
| 56 | && false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * 判断是否是公网ip. |
||
| 61 | * |
||
| 62 | * @param string $ip |
||
| 63 | * |
||
| 64 | * @return bool |
||
| 65 | */ |
||
| 66 | public static function isPublicIp($ip) |
||
| 69 | } |
||
| 70 | } |
||
| 71 |