Check if SSH connection can be made to IP with username.
509635
def _check_ssh(self, *args):
        """"""
        ssh = subprocess.Popen(
            args,
            stdin=subprocess.DEVNULL,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL)
        ssh.wait()
        return ssh.returncode == 0
1170867
def _permission_denied_check(request):
    '''

    '''
    allowed_ips = settings.EUL_INDEXER_ALLOWED_IPS
    if allowed_ips != "ANY" and not request.META['REMOTE_ADDR'] in allowed_ips:
        return True

    return False
875418
def validate(self, value):
        """"""
        try:
            self._choice = IPAddress(value)
        except (ValueError, AddrFormatError):
            self.error_message = '%s is not a valid IP address.' % value
            return False
        if self._choice.is_netmask():
            return True
        else:
            self.error_message = '%s is not a valid IP netmask.' % value
            return False
1205109
def cmd_ssh_user(tar_aminame, inst_name):
    
    if tar_aminame == "Unknown":
        tar_aminame = inst_name
    # first 5 chars of AMI-name can be anywhere in AMI-Name
    userlu = {"ubunt": "ubuntu", "debia": "admin", "fedor": "root",
              "cento": "centos", "openb": "root"}
    usertemp = ['name'] + [value for key, value in list(userlu.items())
                           if key in tar_aminame.lower()]
    usertemp = dict(zip(usertemp[::2], usertemp[1::2]))
    username = usertemp.get('name', 'ec2-user')
    debg.dprint("loginuser Calculated: ", username)
    return username
1300420
def ssh_user(self, cluster='main'):
        """"""
        if not self.config.has_section(cluster):
            raise SystemExit("Cluster '%s' not defined in %s"
                             % (cluster, self.config_file))
        try:
            return self.config.get(cluster, 'ssh_user')
        except NoOptionError:
            return pwd.getpwuid(os.getuid()).pw_name
1124017
def ip
      ip = request.remote_ip
      if ip && Ahoy.mask_ips
        Ahoy.mask_ip(ip)
      else
        ip
      end
    end
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))
1266158
def ssh_session(key_filename,
                username,
                ip_address,
                *cli):
    
    local('ssh -t -i %s %s@%s %s' % (key_filename,
                                     username,
                                     ip_address,
                                     "".join(chain.from_iterable(cli))))
524168
def user_exists(username):
    """"""
    try:
        pwd.getpwnam(username)
        user_exists = True
    except KeyError:
        user_exists = False
    return user_exists
854681
def _can_connect(ip, port):
    """"""
    cs = socket.socket()
    try:
        cs.connect((ip, port))
        cs.close()
        return True
    except socket.error:
        return False
548324
def unlock_keychain(username):
    

    if 'SSH_TTY' not in os.environ:
        return

    # Don't unlock if we've already seen this user.
    if username in _unlocked:
        return

    _unlocked.add(username)

    if sys.platform == 'darwin':
        sys.stderr.write("You are running under SSH. Please unlock your local OS X KeyChain:\n")
        subprocess.call(['security', 'unlock-keychain'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
114068
def validate_ip(self):
        
        if self.request.app.get('_check_ip', False):
            ip_address, accept = self.check_ip()
            if not accept:
                raise web.HTTPUnauthorized()
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
122426
protected function checkIP()
    {
        if (getenv("HTTP_CLIENT_IP"))
            $this->_ip = getenv("HTTP_CLIENT_IP");
        elseif (getenv("HTTP_X_FORWARDED_FOR"))
            $this->_ip = getenv("HTTP_X_FORWARDED_FOR");
        else
            $this->_ip = getenv("REMOTE_ADDR");
    }
1120088
async def async_connect(self):
        """"""

        kwargs = {
            'username': self._username if self._username else None,
            'client_keys': [self._ssh_key] if self._ssh_key else None,
            'port': self._port,
            'password': self._password if self._password else None,
            'known_hosts': None
        }

        self._client = await asyncssh.connect(self._host, **kwargs)
        self._connected = True
457154
def find_ssh_pub_key(self, name):
        
        return bool(self.nova.keypairs.findall(name=name))
1068167
def is_ssh_available(host, port=22):
    
    s = socket.socket()
    try:
        s.connect((host, port))
        return True
    except:
        return False