Helperfunction, if IPv6 in NET_ADDR/PREFIX

@param string $UserIP
@param string $net_addr
@param integer $net_mask
@return boolean
@access public
5485
protected static function checkIp6InNetwork($UserIP, $net_addr=0, $net_mask=0)
    {
        if ($net_mask <= 0)
        {
            return false;
        }
        // UserIP to bin
        $UserIP = static::expandNotationIpv6($UserIP);
        $Parts  = explode(':', $UserIP);
        $Ip = array('', '');
        for ($i = 0; $i < 8; $i++)
        {
            $Ip[0] .= str_pad(base_convert($Parts[$i], 16, 2), 16, 0, STR_PAD_LEFT);
        }
        // NetAddr to bin
        $net_addr = static::expandNotationIpv6($net_addr);
        $Parts    = explode(':', $net_addr);
        for ($i = 0; $i < 8; $i++)
        {
            $Ip[1] .= str_pad(base_convert($Parts[$i], 16, 2), 16, 0, STR_PAD_LEFT);
        }
        // compare the IPs
        return (substr_compare($Ip[0],$Ip[1],0,$net_mask) === 0);
    }
228247
function ispublic($addr) {
		return (bool)filter_var($addr,FILTER_VALIDATE_IP,
			FILTER_FLAG_IPV4|FILTER_FLAG_IPV6|
			FILTER_FLAG_NO_PRIV_RANGE|FILTER_FLAG_NO_RES_RANGE);
	}
304339
def resolve_network_cidr(ip_address):
    '''
    
    '''
    netmask = get_netmask_for_address(ip_address)
    return str(netaddr.IPNetwork("%s/%s" % (ip_address, netmask)).cidr)
151149
def _get_ipv6_network_from_address(address):
    
    if address['addr'].startswith('fe80') or address['addr'] == "::1":
        return None

    prefix = address['netmask'].split("/")
    if len(prefix) > 1:
        netmask = prefix[1]
    else:
        netmask = address['netmask']
    return netaddr.IPNetwork("%s/%s" % (address['addr'],
                                        netmask))
313682
def in_subnet(cidr, addr=None):
    '''
    
    '''
    try:
        cidr = ipaddress.ip_network(cidr)
    except ValueError:
        log.error('Invalid CIDR \'%s\'', cidr)
        return False

    if addr is None:
        addr = ip_addrs()
        addr.extend(ip_addrs6())
    elif not isinstance(addr, (list, tuple)):
        addr = (addr,)

    return any(ipaddress.ip_address(item) in cidr for item in addr)
1174887
public static function netMatch($CIDR, $IP)
    {
        /* TODO: IPV6 */
        if (is_array($CIDR)) {
            foreach ($CIDR as &$v) {
                if (self::netMatch($v, $IP)) {
                    return true;
                }
            }

            return false;
        }

        $e = explode('/', $CIDR, 2);

        if (!isset($e[1])) {
            return $e[0] === $IP;
        }

        return (ip2long($IP) & ~((1 << (32 - $e[1])) - 1)) === ip2long($e[0]);
    }
524042
def natural_ipv4_netmask(ip, fmt='prefixlen'):
    '''
    
    '''
    bits = _ipv4_to_bits(ip)

    if bits.startswith('11'):
        mask = '24'
    elif bits.startswith('1'):
        mask = '16'
    else:
        mask = '8'

    if fmt == 'netmask':
        return cidr_to_ipv4_netmask(mask)
    else:
        return '/' + mask
364817
def enable_static_ip_config_v6(self, ipv6_address, ipv6_network_mask_prefix_length):
        
        if not isinstance(ipv6_address, basestring):
            raise TypeError("ipv6_address can only be an instance of type basestring")
        if not isinstance(ipv6_network_mask_prefix_length, baseinteger):
            raise TypeError("ipv6_network_mask_prefix_length can only be an instance of type baseinteger")
        self._call("enableStaticIPConfigV6",
                     in_p=[ipv6_address, ipv6_network_mask_prefix_length])
1158821
def hasIP(self, ip):
        """"""

        for f in self.features:
            if (f.prop.startswith("net_interface.") and
                    f.prop.endswith(".ip") and f.value == ip):
                return True
        return False
1259435
def in_subnet(cidr, addrs=None):
    
    for address in addrs:
        if ip_in_subnet(address, cidr):
            return True
    return False
492995
def in6_addrtomac(addr):
    
    mask = inet_pton(socket.AF_INET6, "::ffff:ffff:ffff:ffff")
    x = in6_and(mask, inet_pton(socket.AF_INET6, addr))
    ifaceid = inet_ntop(socket.AF_INET6, x)[2:]
    return in6_ifaceidtomac(ifaceid)
437277
public static function check_ipv6($ip)
	{
		$ip = self::uncompress($ip);
		list($ipv6, $ipv4) = self::split_v6_v4($ip);
		$ipv6 = explode(':', $ipv6);
		$ipv4 = explode('.', $ipv4);
		if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4)
		{
			foreach ($ipv6 as $ipv6_part)
			{
				// The section can't be empty
				if ($ipv6_part === '')
					return false;

				// Nor can it be over four characters
				if (strlen($ipv6_part) > 4)
					return false;

				// Remove leading zeros (this is safe because of the above)
				$ipv6_part = ltrim($ipv6_part, '0');
				if ($ipv6_part === '')
					$ipv6_part = '0';

				// Check the value is valid
				$value = hexdec($ipv6_part);
				if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF)
					return false;
			}
			if (count($ipv4) === 4)
			{
				foreach ($ipv4 as $ipv4_part)
				{
					$value = (int) $ipv4_part;
					if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF)
						return false;
				}
			}
			return true;
		}
		else
		{
			return false;
		}
	}
1048467
def is_valid_ipv6_prefix(ipv6_prefix):
    """"""

    # Validate input type
    if not isinstance(ipv6_prefix, str):
        return False

    tokens = ipv6_prefix.split('/')
    if len(tokens) != 2:
        return False

    # Validate address/mask and return
    return is_valid_ipv6(tokens[0]) and is_valid_ip_prefix(tokens[1], 128)
1154778
def has_netmask(interface_name):
    
    for interface in interfaces():
        if interface["name"] == interface_name:
            if interface["netmask"] and len(interface["netmask"]) > 0:
                return True
            return False
    return False
108399
public IPv6Address maskWithNetworkMask(final IPv6NetworkMask networkMask)
    {
        if (networkMask.asPrefixLength() == 128)
        {
            return this;
        }
        else if (networkMask.asPrefixLength() == 64)
        {
            return new IPv6Address(this.highBits, 0);
        }
        else if (networkMask.asPrefixLength() == 0)
        {
            return new IPv6Address(0, 0);
        }
        else if (networkMask.asPrefixLength() > 64)
        {
            // apply mask on low bits only
            final int remainingPrefixLength = networkMask.asPrefixLength() - 64;
            return new IPv6Address(this.highBits, this.lowBits & (0xFFFFFFFFFFFFFFFFL << (64 - remainingPrefixLength)));
        }
        else
        {
            // apply mask on high bits, low bits completely 0
            return new IPv6Address(this.highBits & (0xFFFFFFFFFFFFFFFFL << (64 - networkMask.asPrefixLength())), 0);
        }
    }
742726
def _inet6_ntop(addr):
    
    # IPv6 addresses have 128bits (16 bytes)
    if len(addr) != 16:
        raise ValueError("invalid length of packed IP address string")

    # Decode to hex representation
    address = ":".join(plain_str(bytes_hex(addr[idx:idx + 2])).lstrip('0') or '0'  # noqa: E501
                       for idx in range(0, 16, 2))

    try:
        # Get the longest set of zero blocks. We need to take a look
        # at group 1 regarding the length, as 0:0:1:0:0:2:3:4 would
        # have two matches: 0:0: and :0:0: where the latter is longer,
        # though the first one should be taken. Group 1 is in both
        # cases 0:0.
        match = max(_IP6_ZEROS.finditer(address),
                    key=lambda m: m.end(1) - m.start(1))
        return '{}::{}'.format(address[:match.start()], address[match.end():])
    except ValueError:
        return address
138213
protected function allowIp($ip)
	{
		if(empty($this->ipFilters))
			return true;
		foreach($this->ipFilters as $filter)
		{
			if($filter==='*' || $filter===$ip || (($pos=strpos($filter,'*'))!==false && !strncmp($ip,$filter,$pos)))
				return true;
		}
		return false;
	}