基于paramiko分发公钥到其他机器,有不足的地方还望见谅

#-*- coding: utf-8 -*-
#!/usr/bin/python 
import os
import paramiko
import threading
data='ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvQfqvW1JjYhRVgqYjBCLsTWNx0q/X+IcHdATG0MvJ5Nrew08eoEiy4/rScsUiQaMLaIApTa0Smn5Yg9vP0Z4ESfqMEye3KuBx4R+Y+XvImIL2y3FTkMO9A5ecOegWmJCfoGNBoA9NwYlPF1yAhyhjuVVmqKJc8vgzRo5gTUmAEWaM509l5TuV4OlR6dYzDhHsSXkPeWdpSfUbseg2pUmtOva/n9fgCIj1k7z1nv2SLWxRosnedO20dYIbNR0f1pzH6eMHILDuwohS5n9jbORyqaQaSQ3q9o421pVCOv6PftfPIm9wpN+zRp7pQ6oUTxdxIXkNjFmjL15IOb03SxKEw== root@x-shcs-creditcard-v02'
def ssh2(ip,username,passwd,cmd):
    try:
        paramiko.util.log_to_file('paramiko________.log')
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        #ssh.connect(ip,22,username,passwd,allow_agent=False,look_for_keys=False,timeout=5)
        ssh.connect(ip,22,username,passwd,timeout=5)
        for m in cmd:
            stdin, stdout, stderr = ssh.exec_command(m)
            print stdout.readlines()
            sftp = ssh.open_sftp()
            remote_file = sftp.file('/root/.ssh/authorized_keys', 'wb')
            remote_file.set_pipelined(True)
            remote_file.write(data)
        print '%s\tOK\n'%(ip)
        sftp.close()
        ssh.close()
    except :
        print '%s\tError\n'%(ip)
if __name__=='__main__':
    username="root"
    passwd="Test@2016"
    cmd=['if(! -d /root/.ssh/);then mkdir /root/.ssh/;fi']
    #cmd=['w']
    threads=[]
    print "Begine....."
    for i in range(200,217):
        ip='192.168.50.'+str(i)
        #print ip
        begine=threading.Thread(target=ssh2,args=(ip,username,passwd,cmd))
        #ssh2(ip,username,passwd)
        begine.start()