利用ssh:
window cmd输入 pip install ssh
脚本参考
import ssh
myclient=ssh.SSHClient()
myclient.set_missing_host_key_policy(ssh.AutoAddPolicy())
myclient.connect("192.168.198.200", port=22, username="xxx", password="xxx")
stdin, stdout, stderr = myclient.exec_command("ls -l")
print stdout.read()
stdin, stdout, stderr = myclient.exec_command("touch 123")
利用telnet
import telnetlib
import time
import sys
t=telnetlib.Telnet("192.168.198.136",23,10)
t.set_debuglevel(2)
t.read_until(':~$ ',2)
t.write("touch 111\n")
t.read_until("xxxj@xxx-virtual-machine:",2)
telnet用于无密码情形,ssh用于有密码情形