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

@param portStr the string to check if it's a valid ip port
@return true if it's a valid ip port, false otherwise
498419
public static boolean isValidIpPort(@NotNull final String portStr) {
        return ipPortPattern.matcher(StringUtils.strip(portStr)).matches();
    }
176289
@Override
    public boolean check(String[] pHostOrAddresses) {
        if (allowedHostsSet == null) {
            return true;
        }
        for (String addr : pHostOrAddresses) {
            if (allowedHostsSet.contains(addr)) {
                return true;
            }
            if (allowedSubnetsSet != null && IP_PATTERN.matcher(addr).matches()) {
                for (String subnet : allowedSubnetsSet) {
                    if (IpChecker.matches(subnet, addr)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
125372
public static boolean isIPv4orIPv6Address(String _ipAddress) {
        return IPV4_PATTERN.matcher(_ipAddress).matches() || IPV6_PATTERN.matcher(_ipAddress).matches();
    }
445030
private static boolean isAPortOffset(int offset) {
    return (offset == STANDARD_ASCII_PORT_OFFSET)
                   || (offset == STANDARD_HTTP_PORT_OFFSET)
                   || (offset == STANDARD_SERVLET_PORT_OFFSET)
                   || (offset == STANDARD_CFASL_PORT_OFFSET);
  }
823020
private static boolean isIPAdressValid(final String ip){

        // InetAddress.getByName() validates 'null' as a valid IP (localhost).
        // we do not want that
        if (hasValue(ip)) {
            return IP_ADDR_PATTERN.matcher(ip).matches();
        }
        return false;
    }
162582
public static function isValid($port)
    {
        $port_valid = false;

        if (is_int($port)) {
            $port_valid = self::portIsInValidRange($port);
        } elseif (is_null($port)) {
            $port_valid = true;
        }

        return $port_valid;
    }
1241420
public static boolean isPortAvailable(final int port) {

        try (ServerSocket tcp = new ServerSocket(port);
            DatagramSocket udp = new DatagramSocket(port)) {
            return tcp.isBound() && udp.isBound();
        } catch (Exception e) { //NOSONAR
            return false;
        }
    }
531748
def validate_ip_address(ip_address):
    
    # Validate the IP address
    log = logging.getLogger(mod_logger + '.validate_ip_address')
    if not isinstance(ip_address, basestring):
        log.warn('ip_address argument is not a string')
        return False

    # Ensure there are 3 dots
    num_dots = 0
    for c in ip_address:
        if c == '.':
            num_dots += 1
    if num_dots != 3:
        log.info('Not a valid IP address: {i}'.format(i=ip_address))
        return False

    # Use the socket module to test
    try:
        socket.inet_aton(ip_address)
    except socket.error as e:
        log.info('Not a valid IP address: {i}\n{e}'.format(i=ip_address, e=e))
        return False
    else:
        log.info('Validated IP address: %s', ip_address)
        return True
50805
def _validate_single_port_string(port):
    
    if ' ' not in port or len(port.split(' ')) != 2:
        raise ValueError(
            "Port '{}' should have exactly one space in it".format(port)
        )
    (external, internal) = port.split(' ')
    try:
        external = int(external)
    except ValueError:
        raise ValueError(
            "Port '{}' external port isn't an int".format(port)
        )
    if ':' not in internal:
        raise ValueError(
            "Port '{}' local address should be 'IP:port'".format(port)
        )
    if not internal.startswith('unix:'):
        ip, localport = internal.split(':')
        if ip != 'localhost' and not _is_non_public_numeric_address(ip):
            raise ValueError(
                "Port '{}' internal IP '{}' should be a local "
                "address".format(port, ip)
            )
587068
@Override
    public boolean validateObject(HostAndPort hostAndPort, PooledObject<SocketWriter> socketWriterRef) {
        Socket socket = socketWriterRef.getObject().getSocket();
        return socket.isConnected()
                && socket.isBound()
                && !socket.isClosed()
                && !socket.isInputShutdown()
                && !socket.isOutputShutdown();
    }
1096618
public static boolean verify(String host, String username, String password, int port) throws SMTPException {
	try {
	    return _verify(host, username, password, port);
	}
	catch (MessagingException e) {

	    // check user
	    if (!StringUtil.isEmpty(username)) {
		try {
		    _verify(host, null, null, port);
		    throw new SMTPExceptionImpl("can't connect to mail server, authentication settings are invalid");
		}
		catch (MessagingException e1) {

		}
	    }
	    // check port
	    if (port > 0 && port != 25) {
		try {
		    _verify(host, null, null, 25);
		    throw new SMTPExceptionImpl("can't connect to mail server, port definition is invalid");
		}
		catch (MessagingException e1) {}
	    }

	    throw new SMTPExceptionImpl("can't connect to mail server");
	}
    }
1219911
def is_valid_cidr(string_network):
    
    if string_network.count('/') == 1:
        try:
            mask = int(string_network.split('/')[1])
        except ValueError:
            return False

        if mask < 1 or mask > 32:
            return False

        try:
            socket.inet_aton(string_network.split('/')[0])
        except socket.error:
            return False
    else:
        return False
    return True
512548
public static boolean isValidArg(String arg) {
    final String[] args = arg.split(":");
    if (args.length != 2) {
      return false;
    }

    final String ip = args[1];
    return InetAddresses.isInetAddress(ip);
  }
346197
def is_valid_ip_pattern(ip):
    """"""
    ip = ip.replace('*', '1')
    try:
        socket.inet_aton(ip)
        return True
    except socket.error:
        # Not a valid IPv4 address pattern
        return False
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)
518957
private static boolean isPortOpen(InetAddress pAddress, int pPort) {
        Socket socket = null;
        try {
            socket = new Socket();
            socket.setReuseAddress(true);
            SocketAddress sa = new InetSocketAddress(pAddress, pPort);
            socket.connect(sa, 200);
            return socket.isConnected();
        } catch (IOException e) {
            return false;
        } finally {
            if (socket != null) {
                try {
                    socket.close();
                } catch (IOException e) {
                    // Best effort. Hate that close throws an IOException, btw. Never saw a real use case for that.
                }
            }
        }
    }
1232131
public static boolean isThisAGpsPort( String port ) throws Exception {
        SerialPort comPort = SerialPort.getCommPort(port);
        comPort.openPort();
        comPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 100, 0);

        int waitTries = 0;
        int parseTries = 0;
        while( true && waitTries++ < 10 && parseTries < 2 ) {
            while( comPort.bytesAvailable() == 0 )
                Thread.sleep(500);

            byte[] readBuffer = new byte[comPort.bytesAvailable()];
            int numRead = comPort.readBytes(readBuffer, readBuffer.length);
            if (numRead > 0) {
                String data = new String(readBuffer);
                String[] split = data.split("\n");
                for( String line : split ) {
                    if (SentenceValidator.isSentence(line)) {
                        return true;
                    }
                }
                parseTries++;
            }
        }

        return false;
    }