手机看片精品高清国产日韩,色先锋资源综合网,国产哺乳奶水91在线播放,乱伦小说亚洲色图欧洲电影

幫助中心 >  技術知識庫 >  網站相關 >  網站運營 >  模擬ssh登陸執(zhí)行遠程服務器腳本(python、php版)

模擬ssh登陸執(zhí)行遠程服務器腳本(python、php版)

2017-12-21 22:00:23 12043

以下是分別用python和php模擬ssh登錄遠程服務器,執(zhí)行服務器上腳本的demo:

  • python版本

    import paramikodef sshclient_execmd(hostname, port, username, password, execmd):s = paramiko.SSHClient()s.set_missing_host_key_policy(paramiko.AutoAddPolicy())s.connect(hostname, port, username, password)stdin, stdout, stderr = s.exec_command(execmd)stdin.write("Y")print stdout.read()s.close()def main():hostname = '172.1.1.103' #遠程服務器ipport = 22 #ssh端口username = 'root' #ssh登錄用戶名password = '123456' #ssh登錄密碼execmd = "php /root/1.php" #執(zhí)行遠程服務器上的php文件sshclient_execmd(hostname, port, username, password, execmd)if __name__ == "__main__":main()
  • php版

    <?php$host = '172.1.1.103';$port = 22;$user = 'root';$password = '123456';$execmd = 'php /root/1.php';$connection = ssh2_connect($host, $port);if (ssh2_auth_password($connection, $user, $password)) {echo "Authentication Successful! ";} else {die('Authentication Failed...');}$stream = ssh2_exec($connection,$execmd);stream_set_blocking($stream, true);$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);echo stream_get_contents($stream_out);


提交成功!非常感謝您的反饋,我們會繼續(xù)努力做到更好!

這條文檔是否有幫助解決問題?

非常抱歉未能幫助到您。為了給您提供更好的服務,我們很需要您進一步的反饋信息:

在文檔使用中是否遇到以下問題: