Validates attributes to determine if the values contain valid IP addresses.

 Set the :no_mask option to restrict the IP address to singular addresses only.
356300
def validate_each(record, attribute, value)
      begin
        unless value.blank?
          IPAddr.new(value)
          if options[:no_mask]
            if value =~ /\//
              record.errors[attribute] << (options[:message] || 'must not contain a mask')
            end
          elsif options[:require_mask]
            unless value =~ /\//
              record.errors[attribute] << (options[:message] || 'must contain a mask')
            end
          end
        end
      rescue IPAddr::InvalidAddressError
        record.errors[attribute] << (options[:message] || 'is not a valid IP address')
      end
    end
911974
def _is_valid_netmask(self, netmask):
        
        mask = netmask.split('.')
        if len(mask) == 4:
            try:
                for x in mask:
                    if int(x) not in self._valid_mask_octets:
                        return False
            except ValueError:
                # Found something that isn't an integer or isn't valid
                return False
            for idx, y in enumerate(mask):
                if idx > 0 and y > mask[idx - 1]:
                    return False
            return True
        try:
            netmask = int(netmask)
        except ValueError:
            return False
        return 0 <= netmask <= self._max_prefixlen
1086074
def _is_hostmask(self, ip_str):
        
        bits = ip_str.split('.')
        try:
            parts = [x for x in map(int, bits) if x in self._valid_mask_octets]
        except ValueError:
            return False
        if len(parts) != len(bits):
            return False
        if parts[0] < parts[-1]:
            return True
        return False
1326745
def __ip_addr(addr, address_family=socket.AF_INET):
    '''
    
    '''
    mask_max = '32'
    if address_family == socket.AF_INET6:
        mask_max = '128'

    try:
        if '/' not in addr:
            addr = '{addr}/{mask_max}'.format(addr=addr, mask_max=mask_max)
    except TypeError:
        return False

    ip, mask = addr.rsplit('/', 1)

    # Verify that IP address is valid
    try:
        socket.inet_pton(address_family, ip)
    except socket.error:
        return False

    # Verify that mask is valid
    try:
        mask = int(mask)
    except ValueError:
        return False
    else:
        if not 1 <= mask <= int(mask_max):
            return False

    return True
137683
def ip_addresses(self, value):
        
        if not isinstance(value, list):
            raise ValueError('ip_addresses value must be a list')
        # in soem cases self.data might be none, so let's instantiate an empty dict
        if self.data is None:
            self.data = {}
        # update field
        self.data['ip_addresses'] = ', '.join(value)
1291328
def allowed_ips=(ips)
      ips = ips.to_s.split(',') if ips.is_a? String

      @allowed_ips = ips
    end
405495
def remove_exclusion(host_or_ip)
      asset = host_or_ip
      unless host_or_ip.respond_to?(:host) || host_or_ip.respond_to?(:from)
        # Attept to convert String to appropriate object.
        asset = HostOrIP.convert(host_or_ip)
      end
      @asset_exclusions = asset_exclusions.reject { |a| a.eql? asset }
    end
1047237
def _split_optional_netmask(address):
    """"""
    addr = str(address).split('/')
    if len(addr) > 2:
        raise AddressValueError("Only one '/' permitted in %r" % address)
    return addr
1039409
private static boolean containsAddress(final InetAddress network, final InetAddress netmask, final InetAddress ip) {
        LOGGER.debug("Checking IP address: [{}] in [{}] by [{}]", ip, network, netmask);
        val networkBytes = network.getAddress();
        val netmaskBytes = netmask.getAddress();
        val ipBytes = ip.getAddress();
        /* check IPv4/v6-compatibility or parameters: */
        if (networkBytes.length != netmaskBytes.length || netmaskBytes.length != ipBytes.length) {
            LOGGER.debug("Network address [{}], subnet mask [{}] and/or host address [{}]" + " have different sizes! (return false ...)", network, netmask, ip);
            return false;
        }
        /* Check if the masked network and ip addresses match: */
        for (var i = 0; i < netmaskBytes.length; i++) {
            val mask = netmaskBytes[i] & HEX_RIGHT_SHIFT_COEFFICIENT;
            if ((networkBytes[i] & mask) != (ipBytes[i] & mask)) {
                LOGGER.debug("[{}] is not in [{}]/[{}]", ip, network, netmask);
                return false;
            }
        }
        LOGGER.debug("[{}] is in [{}]/[{}]", ip, network, netmask);
        return true;
    }
805970
protected void doAddressPresentationRestricted() {

        if (this.addressRepresentationRestrictedIndicator != _APRI_NOT_AVAILABLE)
            return;
        // NOTE 1 If the parameter is included and the address presentation
        // restricted indicator indicates
        // address not available, octets 3 to n( this are digits.) are omitted,
        // the subfields in items a - odd/evem, b -nai , c - ni and d -npi, are
        // coded with
        // 0's, and the subfield f - filler, is coded with 11.
        this.oddFlag = 0;
        this.natureOfAddresIndicator = 0;
        this.numberingPlanIndicator = 0;
        this.internalNetworkNumberIndicator = 0;

        this.screeningIndicator = _SI_NETWORK_PROVIDED;
        this.setAddress("");
    }
910214
def __ipv4_netmask(value):
    ''''''
    valid, errmsg = False, 'dotted quad or integer CIDR (0->32)'
    valid, value, _ = __int(value)
    if not (valid and 0 <= value <= 32):
        valid = salt.utils.validate.net.netmask(value)
    return (valid, value, errmsg)
67619
private function validateInputs($ip_address, $network_size)
    {
        if (!filter_var($ip_address, FILTER_VALIDATE_IP)) {
            throw new \UnexpectedValueException("IP address $ip_address not valid.");
        }
        if (($network_size < 1) || ($network_size > 32)) {
            throw new \UnexpectedValueException("Network size $network_size not valid.");
        }
    }
1116480
def valid_address(address):
    
    if not address:
        return False

    components = str(address).split(':')
    if len(components) > 2 or not valid_hostname(components[0]):
        return False

    if len(components) == 2 and not valid_port(components[1]):
        return False

    return True
171146
def validation_regex
      {
        :address             => [HOSTNAME_REGEX, DOMAIN_REGEX, IP_V4_REGEX, IP_V6_REGEX],
        :anything            => [/.*/],
        :bool                => [TRUEFALSE_REGEX],
        :command             => [SIMPLE_COMMAND_REGEX],
        :gsm_adapter         => [ADAPTER_REGEX],
        :hostname            => [HOSTNAME_REGEX],
        :interface           => [INTERFACE_REGEX],
        :ip                  => [IP_V4_REGEX, IP_V6_REGEX],
        :ipv6                => [IP_V6_REGEX],
        :ipv4                => [IP_V4_REGEX],
        :json                => [JsonValidator],
        :mac                 => [MAC_REGEX],
        :snapi_function_name => [SNAPI_FUNCTION_NAME],
        :on_off              => [ON_OFF_REGEX],
        :port                => [PORT_REGEX],
        :uri                 => [URI_REGEX],
      }
    end
354074
def reject_all_values_if_none(source_list)
      if source_list.length > 1
        source_list.reject { |value| value == NONE }
      else
        source_list
      end
    end
906017
def valid_ips(self):
        

        if self._valid_ips is None:
            self._valid_ips = []

            if self.subject_alt_name_value:
                for general_name in self.subject_alt_name_value:
                    if general_name.name == 'ip_address':
                        self._valid_ips.append(general_name.native)

        return self._valid_ips
1348829
def validate_none_of(values):
    
    def none_of_validator(field, data):
        options = values
        if callable(options):
            options = options()
        if field.value in options:
            raise ValidationError('none_of', choices=str.join(', ', options))
    return none_of_validator