The Python and Cisco thing

Source: Internet
Author: User

It took me one hours to study the other Python plug-in for the network device Netmiko, which is still full of fun, but I still do not understand how to multi-threading, or have to work hard.

#!/usr/bin/pythonfrom netmiko import connecthandlerimport timeclass cisconetwork:         def __init__ (self):                  pass         def ciscodevice (self,iplist):                  device={' device_type ': ' Cisco_ios ',                            ' IP ':iplist,                           ' username ': ' admin ',                            ' Password ': ' Password.123 '                           }                  print  "connect to network device... % S " % (IPList)                   self.connect = connecthandler (**device)                   self.connect.enable ()                   time.sleep (0.5)          def gethostname (self):                  #用来获取设备的hostname              &nbsP;   self.hostname = self.connect.find_prompt ()                  self.hostname = self.hostname.replace ("# "," ")                 print  self.hostname        def show (Self,cmd):                   #执行命令                   self.output =  Self.connect.send_command (CMD)                   print self.output        def close ( Self):                 Self.connect.close () If __name__ ==  ' __main__ ':        print  "[+] This  Program is beging done ... "        for iplist  in open ("/opt/other/ip.txt"):                 switch = cisconetwork ()                  switch. Ciscodevice (IPList)                  switch.gethostname ()                  switch.show (' Show ip int brief ')


The Python and Cisco thing

Related Article

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.