Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pexpect import pxssh
- import getpass
- def connect(hostname, username, password, port):
- s = pxssh.pxssh()
- if port:
- s.login(hostname, username, password, port)
- else:
- s.login(hostname, username, password)
- return s
- def enviar_comando(s, comando):
- s.sendline(comando) # run a command
- s.prompt() # match the prompt
- print(s.before) # print everything before the prompt.
- def disconnect(s):
- print("[+] Saindo do console SSH")
- s.logout()
- def main():
- try:
- hostname = raw_input('hostname: ')
- username = raw_input('username: ')
- password = getpass.getpass('password: ')
- port = ('port='+raw_input('port: '))
- s = connect(hostname, username, password, port)
- print "[!] Digite q ou Q para sair do Shell Remoto"
- shell = raw_input(">")
- while True:
- enviar_comando(s, shell)
- print "[!] Digite q ou Q para sair do Shell Remoto"
- shell = raw_input(">")
- if shell == 'q' or shell == 'Q':
- break
- disconnect(s)
- except Exception as e:
- print("pxssh failed on login.")
- print(e)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement