diff options
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -430,6 +430,32 @@ static function cidr_match($ip, $cidrs) /** + * check whether an IP address is a private, loopback or link-local address. + * Supports IPv6 and IPv6 + * @param $ip IP address as string (192.168.42.123, + * 2a02:169:200:d:0:1337:babe:d00d) + * @return true if $ip is in a private, loopback or link-local network block + */ +static function is_private_ip($ip) +{ + $private_cidrs = [ + '10.0.0.0/8', + '127.0.0.0/8', + '169.254.0.0/16', + '172.16.0.0/12', + '192.0.0.0/24', + '192.168.0.0/16', + '198.18.0.0/15', + '::1/128', + 'fc00::/7', + 'fe80::/64', + ]; + + return it::cidr_match($ip, $private_cidrs); +} + + +/** * Convert regex for preg (adds and escapes delimiter, adds modifiers) * @param $pattern Regex to convert * @param $p['casesensitive'] Regex is case sensitive (omit modifier i) |