美文网首页
Python之pexpect

Python之pexpect

作者: Sund4y | 来源:发表于2018-05-12 17:12 被阅读0次

忽然发现了pexpect模块,感觉telnet ftp什么的单独模块弱爆了,都不如这个来的简单暴力通用。

导入pexpect

import pexpect

cmd='ftp xx.xx.xx.xx'

child=pexpect.spawn(cmd,timeout=5)    #创建子进程

index=child.expect(["Name.*",pexpect.EOF,pexpect.TIMEOUT])

  #匹配到Name时index为0,其他情况为1,根据提供的匹配参数叠加index值,EOF为异常模块,TIMEOUT为超时异常,可加可不加这两个模块

if index==0:

    child.sendline(usename)    #sendline为发送指令操作

child.close(force=True)   #强制关闭服务

具体调用模块如下:

相关文章

网友评论

      本文标题:Python之pexpect

      本文链接:https://www.haomeiwen.com/subject/nnrhdftx.html