Python Fortress machine

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.