Ejemplo n.º 1
0
def main():
    ## create session object
    sshsession = paramiko.SSHClient()
    print(sshsession)
    sshsession.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    mykey = paramiko.RSAKey.from_private_key_file("/home/student/.ssh/id_rsa")

    ## create SSH connection
    sshsession.connect(hostname='10.10.2.3', username='******', pkey=mykey)
    print(sshsession)

    our_commands = [
        "touch sshworked.txt", "touch create.txt", "touch file3.txt", "ls"
    ]

    for x in our_commands:
        ## call our imported function and save the value returned
        resp = cmdissue(x, sshsession)
        ## if returned response is not null, print it out
        if resp != "":
            print(resp)

    ## end the SSH connection
    sshsession.close()
Ejemplo n.º 2
0
def main():
  ## create session object
  sshsession = paramiko.SSHClient()
  sshsession.set_missing_host_key_policy(paramiko.AutoAddPolicy())

  mykey = paramiko.RSAKey.from_private_key_file("/home/student/.ssh/id_rsa")
  
  ## create SSH connection
  sshsession.connect(hostname='10.10.2.3', username='******', pkey=mykey)
  

  #challenge 1: create function that returns list of commands
  def getCommands():
      our_commands = []
      while True:
          command = input("What command would you like to issue? Enter 'done' when done ").lower()
          if command == "done":
              return our_commands
          else:
              our_commands.append(command)
              

  
  for x in getCommands():
    ## call our imported function and save the value returned
    resp = cmdissue(x, sshsession)
    ## if returned response is not null, print it out
    if resp != "":
      print(resp)
  
  ## end the SSH connection
  sshsession.close()