- 工信部備案號 滇ICP備05000110號-1
- 滇公安備案 滇53010302000111
- 增值電信業(yè)務經營許可證 B1.B2-20181647、滇B1.B2-20190004
- 云南互聯網協會理事單位
- 安全聯盟認證網站身份V標記
- 域名注冊服務機構許可:滇D3-20230001
- 代理域名注冊服務機構:新網數碼
以下是分別用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ù)努力做到更好!
這條文檔是否有幫助解決問題?
售前咨詢
售后咨詢
備案咨詢
二維碼
TOP