1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #Import Paramiko4 #msg = " " "5 #\ (≧▽≦)/Welcome to the surface of the strongest springboard machine \ (≧▽≦)/6 # """7 #Print (msg)8 ## Create a Sshclient object9 #ssh = Paramiko. Sshclient ()Ten ## Allow trusted hosts to be automatically added to the Host_allow list, this method must be placed before the Connect method One #Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) A ## Call the Connect method to connect to the server - #ssh.connect (hostname= ' 192.168.92.172 ', port=22,username= ' Yinqiuliang ', password= ' 123.com ') - ## Execute Command the # - #While True: - #input_chose = input ("Please enter the operation command for the server:") - #stdin, stdout, stderr = Ssh.exec_command (input_chose) + ## Results are placed in the stdout, if any errors are placed in the stderr - #print (Stdout.read (). Decode ()) + # A #ssh.close () at ImportParamiko -msg =""" - \ (≧▽≦)/Welcome to the surface of the strongest springboard machine \ (≧▽≦)/ - """ - Print(msg) - #t = Paramiko. Transport (("192.168.92.172", ") ") in #t.connect (username= "Yinqiuliang", password= "123.com") - #ssh = Paramiko. Sshclient () to #Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) + #ssh.connect ("192.168.92.172", "Yinqiuliang" , "123.com") - #stdin, stdout, stderr = Ssh.exec_command ("df-h") the #print (Stdout.read (). Decode ()) * #ssh.close () $ #Class Server (host):Panax Notoginseng #def __delattr__ (self, host,user,pwd): - #self.host = Host the #self.user = user + #self.pwd = pwd A the defServer (HOST,PORT,USER,PWD): +SSH =Paramiko. Sshclient () - Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) $Ssh.connect (host, Port, user, pwd,timeout=30) $ whileTrue: -Res_choise = input ("Please enter an action command for the server:") - #Print (res) the ifRes_choise = ='Exit': - exit ()Wuyi elifLen (res_choise) = =0: the Continue - Wu #stdin, stdout, stderr = Ssh.exec_command (res_choise) -stdin, stdout, stderr =Ssh.exec_command (res_choise) AboutRes, err =Stdout.read (), Stderr.read () $Resuilt = ResifResElseErr - Print("[%s]". Center (50,"-") %host) - Print(Resuilt.decode ()) - #print (Stdout.read (). Decode ()) A #print (Stdin.read (). Decode ()) + #print (Stderr.read (). Decode ()) the ssh.close () - #def command (): $ #res = input ("Please enter the operation command for the server:") the ##print (RES) the #return res the the if __name__=='__main__': - #command (' df-h ') inServer"192.168.92.172", 22,"Yinqiuliang","123.com")
Python Fortress machine