Checks if a provided address is actively listening for incoming connections

@param {string} host the host to connect to
@param {number} port the port to check for availability
495574
function checkAvailable(host, port) {
  return new Promise(function(resolve, reject) {
    const socket = new net.Socket();

    socket.on('connect', () => {
      cleanupSocket(socket);
      resolve(true);
    });

    socket.on('error', err => {
      cleanupSocket(socket);
      if (err.code !== 'ECONNREFUSED') {
        return reject(err);
      }

      resolve(false);
    });

    socket.connect({ port: port, host: host });
  });
}
185927
function _filterHost($host)
    {
        if (strstr($host, ':') !== false)
            throw new \InvalidArgumentException('Host name can`t contains port number.');

        $host = strtolower($host);
        return $host;
    }
714912
function probeServer(address, port, callback) {
    address = address || 'localhost';
    port    = port || 443;

    pingServer({
        address:  address,
        port:     port,
        attempts: 1,
        timeout:  5000
    }, function(err, data) {
        var available = data.min !== undefined;
        callback(err, available);
    });
}
370031
function () {
        "use strict";
    
        var events = new Events({'bind': this});
    
        /**
         * Triggers the connect:before event that can be extended by binding
         * to beyond.sockets.bind('connect:before', query, host)
         *
         * @param host {string} The host where the connection is going to be stablished
         * @returns {object} The connection query
         */
        this.getConnectionParams = function (host) {
    
            var query = {};
            events.trigger('connect:before', query, host);
            return query;
    
        };
    
    }
281242
@Override
    public void notifyOfConnection(
            int hostId,
            SocketChannel socket,
            SSLEngine sslEngine,
            InetSocketAddress listeningAddress) throws Exception
    {
        networkLog.info("Host " + getHostId() + " receives a new connection from host " + hostId);
        prepSocketChannel(socket);
        // Auxiliary connection never time out
        ForeignHost fhost = new ForeignHost(this, hostId, socket, Integer.MAX_VALUE,
                listeningAddress,
                createPicoNetwork(sslEngine, socket, true));
        putForeignHost(hostId, fhost);
        fhost.enableRead(VERBOTEN_THREADS);
        // Do all peers have enough secondary connections?
        for (int hId : m_peers) {
            if (m_foreignHosts.get(hId).size() != (m_secondaryConnections + 1)) {
                return;
            }
        }
        // Now it's time to use secondary pico network, see comments in presend() to know why we can't
        // do this earlier.
        m_hasAllSecondaryConnectionCreated = true;
}
244816
function hostInDomains(host, domains) {
  if (!defined(domains)) {
    return false;
  }

  host = host.toLowerCase();
  for (var i = 0; i < domains.length; i++) {
    if (host.match("(^|\\.)" + domains[i] + "$")) {
      return true;
    }
  }
  return false;
}
230544
def enable_host_check(self, host):
        
        if not host.active_checks_enabled:
            host.active_checks_enabled = True
            host.modified_attributes |= \
                DICT_MODATTR["MODATTR_ACTIVE_CHECKS_ENABLED"].value
            self.send_an_element(host.get_update_status_brok())
1372213
static boolean isPortAvailable(int port) {
        ServerSocket ss = null;
        try {
            ss = new ServerSocket(port);
            ss.setReuseAddress(true);
            return true;
        } catch (IOException ioe) { // NOSONAR
            return false;
        } finally {
            closeQuietly(ss);
        }
    }
592937
def is_running(self, port):
        """"""
        try:
            con = self.client('localhost:%s' % port)
            con.admin.command('ping')
            return True
        except (AutoReconnect, ConnectionFailure, OperationFailure):
            # Catch OperationFailure to work around SERVER-31916.
            return False
390280
public static void setProxy(String host, String port) {
		System.setProperty(LOCAL_PROXY_HOST_PROPERTY, host);
		System.setProperty(LOCAL_PROXY_PORT_PROPERTY, port);
	}
878274
def __check_port(self, port):
        
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            s.bind((_host(), port))
            return True
        except socket.error:
            return False
        finally:
            s.close()
111781
public void setHttpProxy(String host, int port) {
        if (config == null) {
            config = new AipClientConfiguration();
        }
        this.config.setProxy(host, port, Proxy.Type.HTTP);
    }
448751
protected void connect(String host, int port)
        throws UnknownHostException, IOException
    {
        boolean connected = false;
        try {
            InetAddress address = InetAddress.getByName(host);
            this.port = port;
            this.address = address;

            connectToAddress(address, port, timeout);
            connected = true;
        } finally {
            if (!connected) {
                try {
                    close();
                } catch (IOException ioe) {
                    /* Do nothing. If connect threw an exception then
                       it will be passed up the call stack */
                }
            }
        }
    }
558194
public synchronized boolean isAllowedHost(String host) {
    boolean isIncluded = includes.isEmpty() || includes.contains(host);
    boolean isExcluded = excludes.contains(host);
    return isIncluded && !isExcluded;
  }
183715
private void vaildateHostPort(String host, String port)
    {
        if (host == null || !StringUtils.isNumeric(port) || port.isEmpty())
        {
            logger.error("Host or port should not be null / port should be numeric");
            throw new IllegalArgumentException("Host or port should not be null / port should be numeric");
        }
    }
714488
function checkPort(port, cb) {
  var server = new net.Server();
  server.on('error', function (err) {
    server.removeAllListeners();
    cb(err);
  });
  server.listen(port, function () {
    server.on('close', function () {
      server.removeAllListeners();
      cb(null, port);
    });
    server.close();
  });
}
715443
public boolean isLocalHostname(String host) {
		checkState();
		try {
			InetAddress[] addresses = InetAddress.getAllByName(host);

			Set<InetAddress> stackAddresses = new HashSet<InetAddress>();

			for (ListeningPoint lp : this.provider.getListeningPoints()) {
				InetAddress tmp = InetAddress.getByName(lp.getIPAddress());
				if (tmp != null)
					stackAddresses.add(tmp);
			}

			for (InetAddress ia : addresses) {
				if (stackAddresses.contains(ia))
					return true;
			}

		} catch (UnknownHostException e) {
			if (tracer.isFineEnabled()) {
				tracer.fine("Unknown host",e);
			}
		}

		return false;
	}