vm_setup.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:setup 作者: mechaphish 项目源码 文件源码
def ssh_exec_command(ssh_obj, cmd, prefix=''):
    """
        Execute a command on the ssh connection.
    :param ssh_obj: SSH object.
    :param cmd: command to run.
    :param prefix: Prefix to be used for printing
    :return: stdout and stderr
    """
    try:
        print(prefix+ "[*] Running Command:" + cmd)
        _, stdout_obj, stderr_obj = ssh_obj.exec_command(cmd)
        exit_status = stdout_obj.channel.recv_exit_status()
        if exit_status == 0:
            print(prefix + GREEN_PRINT + "[+] Command:" + cmd + " Completed Successfully" + END_PRINT)
        else:
            print(prefix + RED_PRINT + "[*] Command:" + cmd + " Return Code:" + str(exit_status) + END_PRINT)

    except paramiko.SSHException as e:
        print(prefix + RED_PRINT + "[!] Problem occurred while running command: %s, Error: %s" % (cmd, e) + END_PRINT)
        raise e
    return stdout_obj, stderr_obj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号