Allow ip address.

    :param ips:
    :return:
510081
def allow_ip(*ips: typing.Union[str, ipaddress.IPv4Network, ipaddress.IPv4Address]):
    
    for ip in ips:
        if isinstance(ip, ipaddress.IPv4Address):
            allowed_ips.add(ip)
        elif isinstance(ip, str):
            allowed_ips.add(ipaddress.IPv4Address(ip))
        elif isinstance(ip, ipaddress.IPv4Network):
            allowed_ips.update(ip.hosts())
        else:
            raise ValueError(f"Bad type of ipaddress: {type(ip)} ('{ip}')")
232782
def validate_address!(addr)
      ip = IPAddr.new(addr)

      unless ip.ipv4?
        raise NotImplementedError, 'Only IPv4 is supported by this library'
      end

      if addr.include?('/')
        raise ArgumentError, 'Please specify a host IP address (without mask)'
      end

      addr.to_s
    end
312892
def batch_add_ips(ips):
        
        ips_created = 0
        if len(ips) > 0:
            # for each ip, check if already existent, if not add
            for ip in ips:
                (s0, s1, s2, s3) = ip.split('.')
                (ip_db, is_ip_created) = IP.objects.get_or_create(seg_0=s0, seg_1=s1, seg_2=s2, seg_3=s3, )
                if is_ip_created:
                    ips_created += 1
        return ips_created
745084
def obfuscate_ip(ip):
    
    if is_valid_ipv4(ip):
        res = "0x%s" % "".join(hex(int(x))[2:] for x in ip.split("."))
    else:
        raise ValueError('Invalid IP value %r' % ip)
    assert is_obfuscated_ip(res),  '%r obfuscation error' % res
    return res
1035937
def address(addr):
    

    if ':' in addr:
        # Using rpartition here means we should be able to support
        # IPv6, but only with a strict syntax
        host, _sep, port = addr.rpartition(':')

        # Convert the port to a number
        try:
            port = int(port)
        except ValueError:
            raise ValueError("invalid port number %r" % port)

        addr = (host, port)

    return addr
537458
def deny(ip,
        port=None,
        proto='tcp',
        direction='in',
        port_origin='d',
        ip_origin='d',
        ttl=None,
        comment=''):
    '''
    
    '''
    return _access_rule('deny', ip, port, proto, direction, port_origin, ip_origin, comment)
119740
def is_valid_ip(ip_address):
    
    valid = True
    try:
        socket.inet_aton(ip_address.strip())
    except:
        valid = False
    return valid
597085
def _parse_ip(addr):
    

    # Parse the IP address
    try:
        address = netaddr.IPAddress(addr.strip())
    except (ValueError, netaddr.AddrFormatError):
        return None

    # Canonicalize it, if possible
    if address.version == 6:
        try:
            return address.ipv4()
        except netaddr.AddrConversionError:
            pass

    return address
391387
def get(self, addresses):
        
        request = self._call(GetReverseDns.GetReverseDns, IPs=addresses)
        response = request.commit()
        return response['Value']
482521
def accept(self, addr):
        

        # Add the address to the set
        ip_addr = _parse_ip(addr)
        if ip_addr is None:
            LOG.warn("Cannot add address %r to proxy %s: "
                     "invalid address" % (addr, self.address))
        else:
            self.accepted.add(addr)
1209878
def ip_check(ip, netmask_expected=False):
    
    try:
        if netmask_expected:
            if "/" not in ip:
                raise netaddr.core.AddrFormatError()
            netaddr.IPNetwork(ip)
        else:
            netaddr.IPAddress(ip)
    except netaddr.core.AddrFormatError:
        if netmask_expected:
            raise ArgsError("Not a valid CIDR (%s)" % ip)
        else:
            raise ArgsError("Not a valid IP address (%s)" % ip)
    except Exception as e:
        raise ArgsError("Invalid format: %s" % str(e))
1035513
def validate(self, value):
        """"""
        try:
            self._choice = IPAddress(value)
            return True
        except (ValueError, AddrFormatError):
            self.error_message = '%s is not a valid IP address.' % value
            return False
868545
def address(self, ip, owner=None, **kwargs):
        
        return Address(self.tcex, ip, owner=owner, **kwargs)
388194
def ParseForwardedIps(self, forwarded_ips):
    
    addresses = []
    forwarded_ips = forwarded_ips or []
    for ip in forwarded_ips:
      if ip and (IP_REGEX.match(ip) or IP_ALIAS_REGEX.match(ip)):
        addresses.extend([str(addr) for addr in list(netaddr.IPNetwork(ip))])
      else:
        self.logger.warning('Could not parse IP address: "%s".', ip)
    return addresses
756078
def ip_address(self,
                   container: Container
                   ) -> Union[IPv4Address, IPv6Address]:
        
        r = self.__api.get('containers/{}/ip'.format(container.uid))
        if r.status_code == 200:
            return r.json()
        self.__api.handle_erroneous_response(r)
96425
def ip(ip_addr, return_tuple=True):
    
    regex_ip = __re.compile("^((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))$")
    if return_tuple:
        while not regex_ip.match(ip_addr):
            print("Not a good IP.")
            print("Please try again.")
            ip_addr = input("Please enter a IP address in the following format x.x.x.x: ")
        return ip_addr
    elif not return_tuple:
        if not regex_ip.match(ip_addr):
            return False
        else:
            return True
380711
def get_sds_by_ip(self,ip):
        
        if self.conn.is_ip_addr(ip):
            for sds in self.sds:
                for sdsIp in sds.ipList:
                    if sdsIp == ip:
                        return sds
            raise KeyError("SDS of that name not found")
        else:
            raise ValueError("Malformed IP address - get_sds_by_ip()")