Given an ip string, it checks if it's a valid ip with a regex (see ipPattern attribute)

@param ipStr the string to check if it's a valid ip
@return true if it's a valid ip, false otherwise
338271
public static boolean isValidIp(@NotNull final String ipStr) {
        return ipPattern.matcher(StringUtils.strip(ipStr)).matches();
    }
1023802
private boolean isAllowedAddress(String ipAddress) {
        if (allowedAddresses == null) {
            return false;
        }

        // IPv4
        int offset = ipAddress.lastIndexOf('.');
        if (offset == -1) {
            // IPv6
            offset = ipAddress.lastIndexOf(':');
            if (offset == -1) {
                return false;
            }
        }

        String ipAddressClass = ipAddress.substring(0, offset + 1) + '*';
        return (allowedAddresses.contains(ipAddressClass) || allowedAddresses.contains(ipAddress));
    }
477001
public static boolean isDotQuadIP ( String hostname ) {
        if ( Character.isDigit(hostname.charAt(0)) ) {
            int i, len, dots;
            char[] data;

            i = dots = 0; /* quick IP address validation */
            len = hostname.length();
            data = hostname.toCharArray();
            while ( i < len && Character.isDigit(data[ i++ ]) ) {
                if ( i == len && dots == 3 ) {
                    // probably an IP address
                    return true;
                }
                if ( i < len && data[ i ] == '.' ) {
                    dots++;
                    i++;
                }
            }
        }

        return false;
    }
499501
public static boolean isXML11ValidQName(String str) {

        final int colon = str.indexOf(':');

        if (colon == 0 || colon == str.length() - 1) {
            return false;
        }
       
        if (colon > 0) {
            final String prefix = str.substring(0,colon);
            final String localPart = str.substring(colon+1);
            return isXML11ValidNCName(prefix) && isXML11ValidNCName(localPart);
        }
        else {
            return isXML11ValidNCName(str);
        }
     }
1193576
public static boolean isValidLocalIP(InetAddress ip) throws SocketException   {
        String ipStr = ip.getHostAddress();
        
        Iterator ips = getAllIPAddresses().iterator();
        while (ips.hasNext()) {
            InetAddress ip2 = (InetAddress) ips.next();
            if (ip2.getHostAddress().equals(ipStr)) {
                return true;
            }
        }
        
        return false;
    }
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))
1042142
def is_valid_ipv4_prefix(ipv4_prefix):
    
    if not isinstance(ipv4_prefix, str):
        return False

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

    # Validate address/mask and return
    return is_valid_ipv4(tokens[0]) and is_valid_ip_prefix(tokens[1], 32)
123882
public static boolean isMatchIPByPattern(String whiteList, String localIP) {
        if (StringUtils.isNotBlank(whiteList)) {
            if (StringUtils.ALL.equals(whiteList)) {
                return true;
            }
            for (String ips : whiteList.replace(',', ';').split(";", -1)) {
                try {
                    if (ips.contains(StringUtils.ALL)) { // 带通配符
                        String regex = ips.trim().replace(".", "\\.").replace("*", ".*");
                        Pattern pattern = Pattern.compile(regex);
                        if (pattern.matcher(localIP).find()) {
                            return true;
                        }
                    } else if (!isIPv4Host(ips)) { // 不带通配符的正则表达式
                        String regex = ips.trim().replace(".", "\\.");
                        Pattern pattern = Pattern.compile(regex);
                        if (pattern.matcher(localIP).find()) {
                            return true;
                        }
                    } else {
                        if (ips.equals(localIP)) {
                            return true;
                        }
                    }
                } catch (Exception e) {
                    LOGGER.warn("syntax of pattern {} is invalid", ips);
                }
            }
        }
        return false;
    }
880691
private boolean isTypeValid(char type) {
		return (type == MAPPED_ADDRESS || type == RESPONSE_ADDRESS
				|| type == SOURCE_ADDRESS || type == CHANGED_ADDRESS
				|| type == REFLECTED_FROM || type == XOR_MAPPED_ADDRESS
				|| type == ALTERNATE_SERVER || type == XOR_PEER_ADDRESS
				|| type == XOR_RELAYED_ADDRESS || type == DESTINATION_ADDRESS);
	}
620078
public static int ipv4StringToInt(String ipv4Str) {
		byte[] byteAddress = ip4StringToBytes(ipv4Str);
		if (byteAddress == null) {
			return 0;
		} else {
			return NumberUtil.toInt(byteAddress);
		}
	}
633107
protected boolean isMatch(IPListConfig config, String remoteAddr) {
        if (config.getIpList().contains(remoteAddr)) {
            return true;
        }
        try {
            String [] remoteAddrSplit = remoteAddr.split("\\."); //$NON-NLS-1$
            for (String ip : config.getIpList()) {
                String [] ipSplit = ip.split("\\."); //$NON-NLS-1$
                if (remoteAddrSplit.length == ipSplit.length) {
                    int numParts = ipSplit.length;
                    boolean matches = true;
                    for (int idx = 0; idx < numParts; idx++) {
                        if (ipSplit[idx].equals("*") || ipSplit[idx].equals(remoteAddrSplit[idx])) { //$NON-NLS-1$
                            // This component matches!
                        } else {
                            matches = false;
                            break;
                        }
                    }
                    if (matches) {
                        return true;
                    }
                }
            }
        } catch (Throwable t) {
            // eat it
        }
        return false;
    }
1076948
def is_valid_ipv4 (ip):
    
    if not _ipv4_re.match(ip):
        return False
    a, b, c, d = [int(i) for i in ip.split(".")]
    return a <= 255 and b <= 255 and c <= 255 and d <= 255
786700
public static boolean isValidIPAddress(String networkAddress) {
		if (networkAddress != null) {
			String[] split = networkAddress.split("\\.");
			if (split.length == 4) {
				int[] octets = new int[4];
				for (int i=0; i<4; i++) {
					try {
						octets[i] = Integer.parseInt(split[i]);
					} catch (NumberFormatException e) {
						return false;
					}
					if (octets[i] < 0 || octets[i] > 255) {
						return false;
					}
				}
				return true;
			}
		}
		return false;
	}
450651
def matches_ip(cls, ip_str, read_preference=None):
        
        qs = cls.qs_for_ip(ip_str).only('whitelist')
        if read_preference:
            qs = qs.read_preference(read_preference)

        # Return True if any docs match the IP and none of them represent
        # a whitelist
        return bool(qs) and not any(obj.whitelist for obj in qs)
1023047
public boolean isIPAddressInRange(IPAddress address) {
		if (ipSubnetMask == null) {
			return this.ipAddress.equals(address);
		}
		
		int result1 = address.getIPAddress() & ipSubnetMask.getIPAddress();
		int result2 = ipAddress.getIPAddress() & ipSubnetMask.getIPAddress();
		
		return result1 == result2;
	}
1011972
public static function ip_match($ip, $match)
    {
        if (ip2long($match)) {//is an actual IP
            if ($ip == $match) {
                return true;
            }
        } else {//is something weird
            if (strpos($match, '/')) {//if it's a cidr notation
                if (self::cidr_match($ip, $match)) {
                    return true;
                }
            } else {//is a random string (let's say a host name)
                $match = gethostbyname($match);
                if ($ip == $match) {
                    return true;
                } else {
                    return false;
                }
            }
        }
        return false;
    }
713136
def valid_ipv4(ip):
    
    match =  _valid_ipv4.match(ip)
    if match is None:
        return False

    octets  = match.groups()
    if len(octets) != 4:
        return False

    first = int(octets[0])
    if first < 1 or first > 254:
        return False

    for i in range(1, 4):
        octet = int(octets[i])
        if octet < 0 or octet > 255:
            return False

    return True