Connect to host/port and get info
433347
private function getSock()
    {
        // Try connecting
        if (!($sock = @fsockopen($this->host, $this->port, $errno, $errstr, self::timeout))) {
            throw new Exception('Error connecting');
        }

        // Try getting stuff
        $buffer = '';
        while ($mid = @fgets($sock)) {
            $buffer .= $mid;
        }

        // Quit
        @fclose($sock);

        // Output:
        return $buffer;
    }
769288
def host_info(host=None):
    '''
    
    '''
    data = query(host, quiet=True)
    for id_ in data:
        if 'vm_info' in data[id_]:
            data[id_].pop('vm_info')
    __jid_event__.fire_event({'data': data, 'outputter': 'nested'}, 'progress')
    return data
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 */
                }
            }
        }
    }
375012
def _getaddrinfo(self, host: str, family: int=socket.AF_UNSPEC) \
            -> List[tuple]:
        '''
        '''
        event_loop = asyncio.get_event_loop()
        query = event_loop.getaddrinfo(host, 0, family=family,
                                       proto=socket.IPPROTO_TCP)

        if self._timeout:
            query = asyncio.wait_for(query, self._timeout)

        try:
            results = yield from query
        except socket.error as error:
            if error.errno in (
                    socket.EAI_FAIL,
                    socket.EAI_NODATA,
                    socket.EAI_NONAME):
                raise DNSNotFound(
                    'DNS resolution failed: {error}'.format(error=error)
                ) from error
            else:
                raise NetworkError(
                    'DNS resolution error: {error}'.format(error=error)
                ) from error
        except asyncio.TimeoutError as error:
            raise NetworkError('DNS resolve timed out.') from error
        else:
            return results
271747
def main():
   

   args = GetArgs()
   if args.password:
      password = args.password
   else:
      password = getpass.getpass(prompt='Enter password for host %s and '
                                        'user %s: ' % (args.host,args.user))

   context = None
   if hasattr(ssl, '_create_unverified_context'):
      context = ssl._create_unverified_context()
   si = SmartConnect(host=args.host,
                     user=args.user,
                     pwd=password,
                     port=int(args.port),
                     sslContext=context)
   if not si:
       print("Could not connect to the specified host using specified "
             "username and password")
       return -1

   atexit.register(Disconnect, si)

   content = si.RetrieveContent()
   for child in content.rootFolder.childEntity:
      if hasattr(child, 'vmFolder'):
         datacenter = child
         vmFolder = datacenter.vmFolder
         vmList = vmFolder.childEntity
         for vm in vmList:
            PrintVmInfo(vm)
   return 0
1297421
def connect(self):
        """"""
        self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._socket.settimeout(self._connect_timeout)
        SocketError.wrap(self._socket.connect, (self.host, self.port))
        self._socket.settimeout(None)
        self._socket_file = self._socket.makefile('rb')
39220
def get_sockinfo (host, port=None):
    """"""
    family, socktype = socket.AF_INET, socket.SOCK_STREAM
    return socket.getaddrinfo(host, port, family, socktype)
628351
def _connect(self):
        """"""
        try:
            if sys.version_info[:2] >= (2,6):
                self._conn = telnetlib.Telnet(self._amihost, self._amiport, 
                                              connTimeout)
            else:
                self._conn = telnetlib.Telnet(self._amihost, self._amiport)
        except:
            raise Exception(
                "Connection to Asterisk Manager Interface on "
                "host %s and port %s failed."
                % (self._amihost, self._amiport)
                )
615331
def get_conn(host='', username=None, password=None, port=445):
    '''
    
    '''
    if HAS_IMPACKET and not HAS_SMBPROTOCOL:
        salt.utils.versions.warn_until(
            'Sodium',
            'Support of impacket has been depricated and will be '
            'removed in Sodium. Please install smbprotocol instead.'
        )
    if HAS_SMBPROTOCOL:
        log.info('Get connection smbprotocol')
        return _get_conn_smbprotocol(host, username, password, port=port)
    elif HAS_IMPACKET:
        log.info('Get connection impacket')
        return _get_conn_impacket(host, username, password, port=port)
    return False
625521
def get_connection(hostname, username, logger, threads=5, use_sudo=None, detect_sudo=True):
    
    if username:
        hostname = "%s@%s" % (username, hostname)
    try:
        conn = remoto.Connection(
            hostname,
            logger=logger,
            threads=threads,
            detect_sudo=detect_sudo,
        )

        # Set a timeout value in seconds to disconnect and move on
        # if no data is sent back.
        conn.global_timeout = 300
        logger.debug("connected to host: %s " % hostname)
        return conn

    except Exception as error:
        msg = "connecting to host: %s " % hostname
        errors = "resulted in errors: %s %s" % (error.__class__.__name__, error)
        raise RuntimeError(msg + errors)
133660
def connect_tcp(self, address, port):
        """"""
        info('Connecting to TCP address: %s:%d', address, port)
        self._connect_tcp(address, port)
676484
def cmd_connect(node, cmd_name, node_info):
    """"""
    # FUTURE: call function to check for custom connection-info
    conn_info = "Defaults"
    conf_mess = ("\r{0}{1} TO{2} {3} using {5}{4}{2} - Confirm [y/N]: ".
                 format(C_STAT[cmd_name.upper()], cmd_name.upper(), C_NORM,
                        node_info, conn_info, C_HEAD2))
    cmd_result = None
    if input_yn(conf_mess):
        exec_mess = ("\r{0}CONNECTING TO{1} {2} using {4}{3}{1}: ".
                     format(C_STAT[cmd_name.upper()], C_NORM, node_info,
                            conn_info, C_HEAD2))
        ui_erase_ln()
        ui_print(exec_mess)
        (ssh_user, ssh_key) = ssh_get_info(node)
        if ssh_user:
            ssh_cmd = "ssh {0}{1}@{2}".format(ssh_key, ssh_user,
                                              node.public_ips)
        else:
            ssh_cmd = "ssh {0}{1}".format(ssh_key, node.public_ips)
        print("\n")
        ui_print("\033[?25h")  # cursor on
        subprocess.call(ssh_cmd, shell=True)
        ui_print("\033[?25l")  # cursor off
        print()
        cmd_result = True
    else:
        ui_print_suffix("Command Aborted")
        sleep(0.75)
    return cmd_result
576630
def connect(self, hostname=None, port=None):
        
        if hostname is not None:
            self.host = hostname
        conn = self._connect_hook(self.host, port)
        self.os_guesser.protocol_info(self.get_remote_version())
        self.auto_driver = driver_map[self.guess_os()]
        if self.get_banner():
            self.os_guesser.data_received(self.get_banner(), False)
        return conn
552929
def _get_binding_info(hostheader='', ipaddress='*', port=80):
    '''
    
    '''
    ret = r'{0}:{1}:{2}'.format(ipaddress, port, hostheader.replace(' ', ''))

    return ret
1161664
def connect(self, (host, port)):
        '''
        
        '''
        super(GeventTransport, self).connect((host, port), klass=socket.socket)
537062
def connect(host, port, username, password):
        """"""
        # Instantiate ftplib client
        session = ftplib.FTP()

        # Connect to host without auth
        session.connect(host, port)

        # Authenticate connection
        session.login(username, password)
        return session
401572
def _connect(self):
        """"""
        self._soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._soc.connect((self._ipaddr, self._port))
        self._soc.send(_build_request({'cmd': cmd.CMD_MESSAGE_PASSWORD,
                                       'sha': self._password}))