ssh登陆

#/usr/bin/python
#coding:utf8
import pxssh
import getpass
try:
        s = pxssh.pxssh()
        hostname = raw_input('hostname: ')
        username = raw_input('username: ')
        password = getpass.getpass('please input password: ')
        s.login (hostname,username,password)
        s.sendline ('uptime')
        s.prompt()
        print s.before

        s.sendline ('ls -l')
        s.prompt()
        print s.before
        s.sendline ('df')
        s.prompt()
        print s.before
        s.logout()
except pxssh.ExceptionPxssh, e:
        print "pxssh failed on login."
        print str(e)

 

发表回复

Your email address will not be published.

名字 *
电子邮件 *
站点