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'
多線程學習——python腳本批量修改華爲交換機端口配置
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.