Dot11 Guru

802.11, Python, scripting

How to discover Cisco access point modes in a programmatic way

There’s no easy way to view the AP Mode from Cisco CLI, without knowing the AP name. This can create some headaches when it comes to automation, however it is solvable with a bit of manipulation.

The following script illustrates one way, although quick and dirty, to retrieve the AP mode via the command

“Show AP Config General %AP Name%”

Form the SSH Connection using netmiko

from netmiko import ConnectHandler
import string
with ConnectHandler(ip = '10.1.1.1',
        port = 22,
        username = 'username',
        password = 'Password',
        device_type = 'cisco_wlc_ssh') as ch:

Disable CLI paging, and get the AP Name list, Format it

 ch.send_command_timing("config paging disable")
    output = ch.send_command_timing("show ap summary")
    postString = output.split("\n",9)[9]
    content = postString.split("\n")
    content = [i.split(' ')[0] for i in content]

Take the list, and loop through each line to retrieve AP mode. Print

    for i in content:
        apname = i
        apconfig = "show ap config general " + i
        apresult = ch.send_command_timing(apconfig)

        for item in apresult.split("\n"):
            if "AP Mode " in item:
                mode = item.strip()
                trimapmode = mode.partition(". ")[2]
                print(apname + " " + trimapmode)

And the full version of the script:

#!/usr/bin/env python

from netmiko import ConnectHandler
import string
with ConnectHandler(ip = '10.1.1.1',
        port = 22,
        username = 'username',
        password = 'Password',
        device_type = 'cisco_wlc_ssh') as ch:

    ch.send_command_timing("config paging disable")
    output = ch.send_command_timing("show ap summary")
    postString = output.split("\n",9)[9]
    content = postString.split("\n")
    content = [i.split(' ')[0] for i in content]

    for i in content:
        apname = i
        apconfig = "show ap config general " + i
        apresult = ch.send_command_timing(apconfig)

        for item in apresult.split("\n"):
            if "AP Mode " in item:
                mode = item.strip()
                trimapmode = mode.partition(". ")[2]
                print(apname + " " + trimapmode)
Share this:

Leave a Reply