How to automate WLC using Python (CLI)

Updated on May 21, 2020: If you are looking for C9800 wireless controller automation, please refer to my following article, I hope this helps you.
Monitoring IOS-XE device with Netconf API + Grafana + InfluxDB

If you are a wireless network engineer, you may need to frequently obtain logs from Cisco wireless controllers for TAC analysis (yes, TAC always needs show run-config…). show run-config contains almost all WLC information, which is why TAC requires show run-config. If you need to open a TAC case, I suggest you provide them with the following information, which will save each other’s time.

config paging disable

show time
show run-config
show run-config commands
show run-config startup-commands
show client summary
show trapflags
show traplog
show logging
show tech-support

config paging enable

The problem is that these logs take a lot of effort. Can we automate these tasks with Python? The answer is certainly yes. Bruce Eckel once said “Life is short (You need Python)”, I never doubt it.

The following is a simple example of obtaining these logs, which can save the results of executing these commands to a txt file.

from netmiko import ConnectHandler

## device settings
wlc = {'host': '192.168.1.1',
       'port': 22,
       'username': 'admin',
       'password': 'Cisco123',
       'device_type': 'cisco_wlc_ssh'}

wlc_connect = ConnectHandler(**wlc)

## CLI Commands list
wlc_show_commands = ('show time',
                     'show run-config',
                     'show run-config commands',
                     'show run-config startup-commands',
                     'show client summary',
                     'show trapflags',
                     'show traplog',
                     'show logging',
                     'show tech-support'
                     )

## Save to txt file
with open('show.txt', 'w') as f:
    for wlc_show_command in wlc_show_commands:
        f.write(wlc_connect.send_command_w_enter(wlc_show_command))

## close
f.close()
wlc_connect.disconnect()

The following error may occur when executing the above code. Of course, it may not appear, depending on your network environment.

Exception: Error reading SSH protocol banner
Traceback (most recent call last): 

   raise socket.timeout()
socket.timeout

During handling of the above exception, another exception occurred:


    "Error reading SSH protocol banner" + str(e)
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner

This was a problem that bothered me for a long time, until I discovered the banner_timeout parameter. You can define banner_timeout in wlc variable and set it to 10 seconds or longer (depending on your network environment).

Netmiko is a very useful network maintenance tool, the above example is just a simple usage, it can also be used to change the WLC configuration and so on, and it can also be used for other devices, such as Catalyst switches. if you are interested in it, you can visit the Github page for more information.

Netmiko: https://github.com/ktbyers/netmiko

4 Responses

  1. Tams says:

    THANKS FOR THE HEEELP 😀 Was blocked since 1 week !!

  2. Carlos Contreras says:

    Hi have you ever try to handle controller output with a low privilege user that can’t execute paging disable? Since I only have an user with show rights only recently asked on Netmiko forums how can this be handled, they suggested recently a _send_command_more function to input characters requested on the output. This is apparently inside a class call yotc inside netmiko, unfortunately haven’t been able to make it work properly and neither and example, would be interesting if someone on your community could provide some feedback for this use case

    • Haifeng says:

      Hello Carlos,

      Please refer to the following code, hope this helps.


      wlc_connect.send_command_expect(
      "show run-config",
      expect_string="Press Enter to continue")
      while True:
      wlc_connect.write_channel("\r\n")
      time.sleep(0.5)
      output = wlc_connect.read_channel()
      print(output)
      if "(Cisco Controller) >" in output:
      break

      wlc_connect.disconnect()

Leave a Reply

Your email address will not be published.