自动化部署

自动化部署

pexpect

Pexpect 是 Don Libes 的 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Python 模块。 Pexpect 的使用范围很广,可以用来实现与 ssh、ftp 、telnet 等程序的自动交互;可以用来自动复制软件安装包并在不同机器自动安装;还可以用来实现软件测试中与命令行交互的自动化。

import pexpect
import sys

child = pexpect.spawn('ssh std20@123.57.211.212')
child.logfile = sys.stdout
#fout = file('mylog.txt', 'w')
#child.logfile = fout
child.expect('password:')
child.sendline('std20')
child.expect('std20.*')
child.sendline('ls /')
child.expect('std20.*')
child.sendline('exit')
#coding=utf_8

from pexpect import pxssh
import sys

s = pxssh.pxssh()
s.logfile = sys.stdout
hostname = '123.57.211.212'
username = 'std20'
password = 'std20'
s.login(hostname, username, password)
s.sendline('ls /')
s.prom
上一篇:[BUUCTF-Pwn]刷题记录


下一篇:安装anaconda3卡在Unpacking payload ...