Returns a copy of the IP address instance masked with the specified mask.

@since 1.0.0

@param IPAddressInterface $mask The mask.

@return IPAddressInterface The IP address instance.
484896
public function withMask(IPAddressInterface $mask): IPAddressInterface
    {
        $octets = $this->getParts();
        $maskOctets = $mask->getParts();

        for ($i = 0; $i < 4; $i++) {
            $octets[$i] = $octets[$i] & $maskOctets[$i];
        }

        return new self($octets);
    }
309204
public static function ipWithProxy($delimiter = ','): string
    {
        $ip = self::ip();

        if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $ip != $_SERVER['HTTP_X_FORWARDED_FOR']) {
            $ip .= "{$delimiter}{$_SERVER['HTTP_X_FORWARDED_FOR']}";
        }

        return $ip;
    }
443392
public static function inRange(string $ip, string $range): bool
	{
		if(strpos($range, '/') === false)
		{
			$netmask = 128;
		}
		else
		{
			[$range, $netmask] = explode('/', $range, 2);

			if($netmask < 1 || $netmask > 128)
			{
				return false;
			}
		}

		$binNetmask = str_repeat('f', $netmask / 4);

		switch($netmask % 4)
		{
			case 1:
				$binNetmask .= '8';
				break;
			case 2:
				$binNetmask .= 'c';
				break;
			case 3:
				$binNetmask .= 'e';
				break;
		}

		$binNetmask = pack('H*', str_pad($binNetmask, 32, '0'));

		try
		{
			return (inet_pton($ip) & $binNetmask) === inet_pton($range);
		}
		catch(Throwable $e)
		{
			return false;
		}
	}
353164
public function setDefaultAttachmentMask($mask) {
        if(class_exists($mask)) {
            $this->default_attachment_mask = $mask;

            return $this;
        }

        throw new MaskNotFoundException("Unknown mask provided: ".$mask);
    }
1123214
public function withHost(string $host): UriInterface
    {
        $instance = clone $this;
        $instance->host = $this->marshalHost($host);

        return $instance;
    }
834967
protected function getMask(/*# int */ $length = 32)/*# : int */
    {
        $bin = substr(str_repeat('1', $length) . str_repeat('0', 32), 0, 32);
        return ip2long(long2ip(bindec($bin)));
    }
754872
protected function getIPAddress( \Psr\Http\Message\ServerRequestInterface $request )
	{
		$server = $request->getServerParams();
		$flags = FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6;

		if( isset( $server['REMOTE_ADDR'] )
			&& ( $ip = filter_var( $server['REMOTE_ADDR'], FILTER_VALIDATE_IP, $flags ) ) !== false
		) {
			return $ip;
		}
	}
400414
private int computeNetworkPrefixFromMask(IPAddress mask) {
		
		int result = 0;
		int tmp = mask.getIPAddress();
		
		while ((tmp & 0x00000001) == 0x00000001) {
			result++;
			tmp = tmp >>> 1;
		}
		
		if (tmp != 0) {
			return -1;
		}
		
		return result;
	}
857357
protected function fromInotifyMask($mask)
    {
        $mask &= ~IN_ISDIR;
        $event = 0;
        switch ($mask) {
            case (IN_MODIFY):
            case (IN_ATTRIB):
                $event =  FilesystemEvent::MODIFY;
                break;
            case (IN_CREATE):
                $event =  FilesystemEvent::CREATE;
                break;
            case (IN_DELETE):
            case (IN_IGNORED):
                $event =  FilesystemEvent::DELETE;
        }

        return $this->supportsEvent($event) ? $event : false;
    }
17277
protected function getConnectionMask(ConnectionInterface $connection)
    {
        return strtolower(sprintf(
            '%s!%s@%s',
            $connection->getNickname(),
            $connection->getUsername(),
            $connection->getServerHostname()
        ));
    }
348428
def getMask (self, ifname):
        
        if sys.platform == 'darwin':
            return ifconfig_inet(ifname).get('netmask')
        return self._getaddr(ifname, self.SIOCGIFNETMASK)
1031262
public static function bitToIndex(int $mask): int
    {
        if (!self::isSingleBit($mask)) {
            throw new \InvalidArgumentException('Must be single bit');
        }
        return (int)log($mask, 2);
    }
453298
public static function ipToNetAddress($ip)
	{
		$parts = explode('.', $ip);
		$address = '1#';

		foreach ($parts as $int)
		{
			$tmp = dechex($int);

			if (strlen($tmp) != 2)
			{
				$tmp = '0' . $tmp;
			}

			$address .= '\\' . $tmp;
		}

		return $address;
	}
851537
protected function applyIpV6Mask($ip, $maskLength):string
    {
        $masks = ['ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', 'ffff:ffff:ffff:ffff::', 'ffff:ffff:ffff:0000::', 'ffff:ff00:0000:0000::'];
        $packedAddress = inet_pton($masks[$maskLength]);
        $binaryString = pack('a16', $packedAddress);
        return (string)($ip & $binaryString);
    }
1167805
public static function mask($value, $mask)
    {
        if (!Int::is($value) || !Int::is($mask)) {
            throw new \InvalidArgumentException("Both parameters must be integers.");
        }

        return ($value & $mask);
    }
523406
public function setMasks($masks)
    {
        $this->masks = (array) $masks;
        $this->maskValue = array_reduce($this->masks, function ($maskValue, $mask) {
            return $maskValue | $mask;
        });

        return $this;
    }
1005072
public static function getClientIp($safe = true) {
		if (!$safe && env('HTTP_X_FORWARDED_FOR')) {
			$ipaddr = preg_replace('/(?:,.*)/', '', env('HTTP_X_FORWARDED_FOR'));
		} elseif (!$safe && env('HTTP_CLIENT_IP')) {
			$ipaddr = env('HTTP_CLIENT_IP');
		} else {
			$ipaddr = env('REMOTE_ADDR');
		}
		return trim($ipaddr);
	}