Longman\IPTools\Ip::isLocal PHP Method

isLocal() public static method

Checks if an IP is local
public static isLocal ( string $ip ) : boolean
$ip string IP
return boolean true if the IP is local, otherwise false
    public static function isLocal($ip)
    {
        $localIpv4Ranges = array('10.*.*.*', '127.*.*.*', '192.168.*.*', '169.254.*.*', '172.16.0.0-172.31.255.255', '224.*.*.*');
        $localIpv6Ranges = array('fe80::/10', '::1/128', 'fc00::/7');
        if (self::isValidv4($ip)) {
            return self::match($ip, $localIpv4Ranges);
        }
        if (self::isValidv6($ip)) {
            return self::match($ip, $localIpv6Ranges);
        }
        return false;
    }

Usage Example

Example #1
0
 public function testLocal()
 {
     $status = Ip::isLocal('192.168.5.5');
     $this->assertTrue($status);
     $status = Ip::isLocal('fe80::202:b3ff:fe1e:8329');
     $this->assertTrue($status);
 }