A small script to work with, put it up.
Import telnetlibdef get_mac (): coreip= ' three-layer switch IP ' # try: tel = telnetlib. Telnet (COREIP) tel.read_until (' Username: ') tel.write (' three-layer switch account ' + ' \ n ') Tel.read_until (' Password: ') tel.write (' Three-layer switch password ' + ' \ n ') tel.read_until (' > ') tel.write (' ping ' + s_ip + ' \ n ') # data = tel.read_until (' > ') tel.read_until (' > ') tel.write (' dis arp | in ' + s_ip + ' \ n ') data = tel.read_unTil (' > ') data = data.split () print data[16] mac = data[16] return mac# except: print ' bad ' def get_port ():# try: tel = telnetlib. Telnet (IP) tel.read_until (' Username: ') tel.write (' account ' + ' \ n ') tel.read_until (' Password: ') tel.write (' password ' + ' \ n ') tel.read_until (' > ') tel.write (' dis mac-add ' + mac + ' \ n ') &nbSp; raw_data = tel.read_until (' > ') print ' *************** connect to ========>> ',ip if ' Xge ' not in raw_data :# print raw_data data = raw_data.split () # print data if ' GE ' in data[12] : print raw_data# except:print ' Can not connect to %s\n ' %ipwhile true: ipfile = open (' swiplist.txt ') ipall&nbSp; = [ ip.strip (' \ n ') for ip in ipfile.readlines () ] s_ip = raw_input (' input ip add ,such as => 192.168.0.1 \n > ') mac = get_mac () for ip in ipall: get_port () words = raw_input ("input ' yes ' to run Again, input any key to exit: ") if words != ' yes ': Break
This article is from the "July" blog, please be sure to keep this source http://374721.blog.51cto.com/364721/1737000
Find out which port the IP connection is on the switch