Tests if the current pattern allows the given port.

@param {String} port The port to be checked if the pattern allows.
@param {String} protocol Protocol to refer default port.
@return {Boolean}
504787
function (port, protocol) {
        var portRegex = this._matchPatternObject.port,

            // default port for given protocol
            defaultPort = protocol && DEFAULT_PROTOCOL_PORT[protocol];

        // return true if both given port and match pattern are absent
        if (typeof port === UNDEFINED && typeof portRegex === UNDEFINED) {
            return true;
        }

        // convert integer port to string
        (port && typeof port !== STRING) && (port = String(port));

        // assign default port or portRegex
        !port && (port = defaultPort);
        !portRegex && (portRegex = defaultPort);

        // matches * or specific port
        return (
            portRegex === MATCH_ALL ||
            portRegex === port
        );
    }
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;
        }
    }
921406
function getPort (port, callback) {
  const server = net.createServer()

  server.on('error', () => {
    getPort(++port, callback)
  })

  // Explicitly listen on 0.0.0.0 to detect ports used by Docker
  // See: https://github.com/nodejs/node/issues/14034
  server.listen(port, '0.0.0.0', () => {
    server.once('close', () => {
      callback(port)
    })
    server.close()
  })
}
996097
function MSPassportStrategy(options) {
  Strategy.call(this);
  this.name = "mspassport";
  
  var default_options = {
        protocol : "querystring",
        protocolHandler : function() { self.fail("protocolHandler must be implemented if protocol === 'custom'") }        
  };
    
  this.options = _defaults(default_options, options);
}
776769
public static boolean isPortAvailable(int port) {
        StringBuilder builder = new StringBuilder();
        builder.append("Testing port ").append(port).append("\n");
        try (Socket s = new Socket("localhost", port)) {
            // If the code makes it this far without an exception it means
            // something is using the port and has responded.
            builder.append("Port ").append(port).append(" is not available").append("\n");
            return false;
        } catch (IOException e) {
            builder.append("Port ").append(port).append(" is available").append("\n");
            return true;
        } finally {
            log.fine(builder.toString());
        }
    }
641616
@Override
    public boolean hasProtocol(final Protocol p) throws IOException {
        if (p == null) {
            return false;
        }

        try {
            final Packet packet = getPacket(p);
            return packet != null;
        } catch (final Exception e) {
            return false;
        }
    }
495141
function (callback) {
    checkPortStatus(port, host, opts, function (error, statusOfPort) {
      numberOfPortsChecked++
      if (statusOfPort === status) {
        foundPort = true
        callback(error)
      } else {
        port = portList ? portList[numberOfPortsChecked] : port + 1
        callback(null)
      }
    })
  }
1032362
def is_port_default(self):
        ''''''
        if self.scheme in RELATIVE_SCHEME_DEFAULT_PORTS:
            return RELATIVE_SCHEME_DEFAULT_PORTS[self.scheme] == self.port
1062895
function (protocols) {
        if (!protocols) {
            return;
        }

        var updatedProtocols,
            hostAndPath = _.split(this.match.pattern, PROTOCOL_HOST_SEPARATOR)[1];

        if (!hostAndPath) {
            return;
        }

        updatedProtocols = _.intersection(ALLOWED_PROTOCOLS, _.castArray(protocols));
        _.isEmpty(updatedProtocols) && (updatedProtocols = ALLOWED_PROTOCOLS);

        this.match.update({
            pattern: updatedProtocols.join(PROTOCOL_DELIMITER) + PROTOCOL_HOST_SEPARATOR + hostAndPath
        });
    }
939078
function isLegalPort(port: number) : boolean {
  if (typeof port === 'string' && port.trim() === '') {
    return false;
  }
  return +port === (port >>> 0) && port >= 0 && port <= 0xFFFF;
}
638849
public static boolean isUsableLocalPort(int port) {
		if (false == isValidPort(port)) {
			// 给定的IP未在指定端口范围中
			return false;
		}
		try {
			ServerSocketFactory.getDefault().createServerSocket(port, 1, InetAddress.getByName(LOCAL_IP)).close();
			return true;
		} catch (Exception e) {
			return false;
		}
	}
653003
public function set_port($port)
	{
		if ($port === null)
		{
			$this->port = null;
			return true;
		}
		elseif (strspn($port, '0123456789') === strlen($port))
		{
			$this->port = (int) $port;
			$this->scheme_normalization();
			return true;
		}
		else
		{
			$this->port = null;
			return false;
		}
	}
18953
def is_available(self):
        
        if self.scheme in NOOP_PROTOCOLS:
            return True

        if not self.port:
            raise RuntimeError('port is required')

        s = socket.socket()
        try:
            s.connect((self.host, self.port))
        except Exception:
            return False
        else:
            return True
513677
def allow_port(port, proto='tcp', direction='both'):
    '''
    
    '''

    ports = get_ports(proto=proto, direction=direction)
    direction = direction.upper()
    _validate_direction_and_proto(direction, proto)
    directions = build_directions(direction)
    results = []
    for direction in directions:
        _ports = ports[direction]
        _ports.append(port)
        results += allow_ports(_ports, proto=proto, direction=direction)
    return results
881632
function isPortInUse(port) {
  _validatePortFormat(port);
  if (isPlatform('unix')) {
    if (isPlatform('linux') && fileExists('/proc/net')) {
      return _isPortInUseRaw(port);
    } else if (isInPath('netstat')) {
      return _isPortInUseNetstat(port);
    } else {
      throw new Error('Cannot check port status');
    }
  } else {
    throw new Error('Port checking not supported on this platform');
  }
}
602138
public static boolean isTcpPortAvailable(String hostname, int port) {
        try (ServerSocket serverSocket = new ServerSocket()) {
            // setReuseAddress(false) is required only on OSX,
            // otherwise the code will not work correctly on that platform
            serverSocket.setReuseAddress(false);
            serverSocket.bind(new InetSocketAddress(InetAddress.getByName(hostname), port), 1);
            return true;
        } catch (Exception ex) {
            return false;
        }
    }
901564
public static boolean isPortAvailable(int port) {
		try {
			ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(port, 1,
					InetAddress.getByName("localhost"));
			serverSocket.close();
			return true;
		} catch (Exception ex) { // NOSONAR
			return false;
		}
	}