Is IP address currently unused in subnet?

@param string $ipAddress IPv4 address

@return bool

@throws Exception on error
334400
public function isFree($ipAddress) {
        if (!isset($this->current)) {
            throw new BadMethodCallException('You need to call method "load()" first.');
        }

        $longIP = $this->convertIPv4Address($ipAddress);

        return ! $this->isUsed($longIP);
    }
693442
public function locate($ipAddress)
    {
        $response = $this->client->get("json/$ipAddress");

        // Parse body content
        $data = json_decode($response->getBody());

        // Verify response status
        if ($data->status !== 'success') {
            throw new Exception("Request failed ({$data->message})");
        }

        return $this->hydrate([
            'ip'          => $ipAddress,
            'iso_code'    => $data->countryCode,
            'country'     => $data->country,
            'city'        => $data->city,
            'state'       => $data->regionName,
            'state_code'  => $data->region,
            'postal_code' => $data->zip,
            'latitude'    => $data->lat,
            'longitude'   => $data->lon,
            'timezone'    => $data->timezone,
            'continent'   => $this->continents->get($data->countryCode, 'Unknown'),
        ]);
    }
29719
public function frontend_excluded_ip_addresses($request)
    {
        $frontend_excluded_ip_addresses = config('lasallecmsfrontend.frontend_excluded_ip_addresses');

        // "true" = exclude
        if (empty($frontend_excluded_ip_addresses)) return false;

        $requestIPAddress = $this->customAdminAuthChecks->getRequestIPAddress($request);

        return $this->customAdminAuthChecks->ipAddressCheck($frontend_excluded_ip_addresses, $requestIPAddress);
    }
1024072
def check_ip(addr):
    '''
    
    '''

    try:
        addr = addr.rsplit('/', 1)
    except AttributeError:
        # Non-string passed
        return False

    if salt.utils.network.is_ipv4(addr[0]):
        try:
            if 1 <= int(addr[1]) <= 32:
                return True
        except ValueError:
            # Non-int subnet notation
            return False
        except IndexError:
            # No subnet notation used (i.e. just an IPv4 address)
            return True

    if salt.utils.network.is_ipv6(addr[0]):
        try:
            if 8 <= int(addr[1]) <= 128:
                return True
        except ValueError:
            # Non-int subnet notation
            return False
        except IndexError:
            # No subnet notation used (i.e. just an IPv4 address)
            return True

    return False
741322
public function isTwoFactorRequired($ipAddress)
    {
        return $this->definition->isTwoFactorRequired($ipAddress, $this->isTwoFactorEnabled(), $this->getGroup());
    }
159478
public function ipAddress($subject) : bool
    {
        if ($subject === null) {
            return false;
        }
        $v = '' . $subject;
        return $v === '' ? false : !!filter_var($v, FILTER_VALIDATE_IP);
    }
536546
protected function loadIpThrottles($ipAddress)
    {
        $queryBuilder = $this->getEntityManager()->createQueryBuilder();

        $queryBuilder
            ->select('t')
            ->from($this->entityName('ip'), 't')
            ->where('t.createdAt > :interval')
            ->andWhere('t.ip = :ip')
            ->setParameters([
                'interval' => Carbon::now()->subSeconds($this->ipInterval),
                'ip'  => $ipAddress
            ]);

        return new Collection($queryBuilder->getQuery()->getResult());
    }
834234
def is_reserved_ip(self, ip):
        
        theip = ipaddress(ip)
        for res in self._reserved_netmasks:
            if theip in ipnetwork(res):
                return True
        return False
573600
protected function checkAndSetIpPort($ip_address)
    {

        // Test for IPv6
        if (substr_count($ip_address, ':') > 1) {
            // See if we have a port, input should be in the format [::1]:27015 or similar
            if (strstr($ip_address, ']:')) {
                // Explode to get port
                $server_addr = explode(':', $ip_address);

                // Port is the last item in the array, remove it and save
                $this->port_client = (int)array_pop($server_addr);

                // The rest is the address, recombine
                $this->ip = implode(':', $server_addr);

                unset($server_addr);
            } else {
                // Just the IPv6 address, no port defined, fail
                throw new Exception(
                    "The host address '{$ip_address}' is missing the port.  All "
                    . "servers must have a port defined!"
                );
            }

            // Now let's validate the IPv6 value sent, remove the square brackets ([]) first
            if (!filter_var(trim($this->ip, '[]'), FILTER_VALIDATE_IP, ['flags' => FILTER_FLAG_IPV6,])) {
                throw new Exception("The IPv6 address '{$this->ip}' is invalid.");
            }
        } else {
            // We have IPv4 with a port defined
            if (strstr($ip_address, ':')) {
                list($this->ip, $this->port_client) = explode(':', $ip_address);

                // Type case the port
                $this->port_client = (int)$this->port_client;
            } else {
                // No port, fail
                throw new Exception(
                    "The host address '{$ip_address}' is missing the port. All "
                    . "servers must have a port defined!"
                );
            }

            // Validate the IPv4 value, if FALSE is not a valid IP, maybe a hostname.  Try to resolve
            if (!filter_var($this->ip, FILTER_VALIDATE_IP, ['flags' => FILTER_FLAG_IPV4,])
                && $this->ip === gethostbyname($this->ip)
            ) {
                // When gethostbyname() fails it returns the original string
                // so if ip and the result from gethostbyname() are equal this failed.
                throw new Exception("Unable to resolve the host '{$this->ip}' to an IP address.");
            }
        }
    }
832883
protected function ipIsTrustedProxy($ipAddress)
    {
        if (filter_var($ipAddress, FILTER_VALIDATE_IP) === false) {
            return false;
        }
        $allowedProxies = $this->settings['proxies'];
        if ($allowedProxies === '*') {
            return true;
        }
        if (is_string($allowedProxies)) {
            $allowedProxies = array_map('trim', explode(',', $allowedProxies));
        }
        if (!is_array($allowedProxies)) {
            return false;
        }
        foreach ($allowedProxies as $ipPattern) {
            if (IpUtility::cidrMatch($ipAddress, $ipPattern)) {
                return true;
            }
        }
        return false;
    }
16341
private function isTrustedIpAddress($ipAddress)
    {
        foreach ($this->trustedIpRanges as $trustedIpBlock) {
            if ($trustedIpBlock->containsIP($ipAddress)) {
                return true;
            }
        }

        return false;
    }
482261
public function locate($ipAddress)
    {
        $response = $this->client->get("json/$ipAddress");

        $data = json_decode($response->getBody());

        return $this->hydrate([
            'ip'          => $ipAddress,
            'iso_code'    => $data->country_code,
            'country'     => $data->country_name,
            'city'        => $data->city,
            'state'       => $data->region_name,
            'state_code'  => $data->region_code,
            'postal_code' => $data->zip_code,
            'latitude'    => $data->latitude,
            'longitude'   => $data->longitude,
            'timezone'    => $data->time_zone,
            'continent'   => $this->continents->get($data->country_code, 'Unknown'),
        ]);
    }
4934
public function isIPAddressInSubnet($ip_address_string)
    {
        $ip_address = ip2long($ip_address_string);
        list($start_ip, $end_ip) = $this->getIPAddressRangeAsInts();

        return $ip_address >= $start_ip && $ip_address <= $end_ip
            ? true
            : false;
    }
875290
public static function currentIpAddress() {

    //
    // Just get the headers if we can or else use the SERVER global
    //
    if (function_exists('apache_request_headers')) {
      $headers = apache_request_headers();
    } else {
      $headers = $_SERVER;
    }

    //
    // Get the forwarded IP if it exists
    //
    if (
      array_key_exists('X-Forwarded-For', $headers) &&
      filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)
    ) {
      $the_ip = $headers['X-Forwarded-For'];
    }

    elseif (
      array_key_exists('HTTP_X_FORWARDED_FOR', $headers ) &&
      filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)
    ) {
      $the_ip = $headers['HTTP_X_FORWARDED_FOR'];
    }

    else {
      $the_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
    }

    return $the_ip;
  }
348808
public static function tryParse(string $ipAddress): ?IPAddressInterface
    {
        if (!self::myParse($ipAddress, $octets)) {
            return null;
        }

        return new self($octets);
    }
503633
public static function isIP($address)
    {

        //Split the IP address of the form  into parts
        $parts = explode('.', $address);
        //=4 parts
        if (sizeof($parts) != 4) {
            return false;
        }
        foreach ($parts as $part):
            if (empty($part) || !static::number($part) || $part > 255) {
                return false;
            }
        endforeach;

        return true;
    }
499140
public static function reverseIpv4(string $address): bool
    {
        $pattern = '/^((?:[0-9]+\.){1,4})in\-addr\.arpa\.$/i';

        if (1 !== preg_match($pattern, $address, $matches)) {
            return false;
        }

        $octets = explode('.', $matches[1]);
        array_pop($octets); //Remove the last decimal from the array

        foreach ($octets as $octet) {
            if ((int) $octet > 255) {
                return false;
            }
        }

        return true;
    }