Find out which port the IP connection is on the switch

Source: Internet
Author: User

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

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.