频道栏目
首页 > 资讯 > 交换机 > 正文

多线程学习——python脚本批量修改华为交换机端口配置

15-12-03        来源:[db:作者]  
收藏   我要投稿
import  telnetlib,threading
ipfile = open('swiplist.txt')
ipall  = [ ip.strip('\n') for ip in ipfile.readlines() ]
def get_mac(ip):
    try:
        tel = telnetlib.Telnet(ip)
        tel.read_until('Username:')
        tel.write('admin'+'\n')
        tel.read_until('Password:')
        tel.write('password'+'\n')
        tel.read_until('>')
        tel.write('dis mac-add ' + mac +'\n')
        data = tel.read_until('>')
        if 'sticky'   in data:
            print 'telnet '+ ip 
            print data 
        print ip,'done'
    except:print 'can not connect to %s' %ip
threads = []
numbers = range(len(ipall))
mac = raw_input('input mac add ,like => aabb-ccdd-eeff \n >')
for i in numbers:
    t = threading.Thread(target=get_mac,args=(ipall[i],))
    threads.append(t)
     
if __name__ == '__main__':
    for i in numbers:
        threads[i].start()
         
print 'all done'

 

相关TAG标签
上一篇:CentOS ZooKeeper install
下一篇:802.11无线技术
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站