artofrf.com

Ali's Technology Blog

Menu
  • Home
  • Important Links
  • About Me
  • Tools and Scripts
Menu

My first Python script

Posted on March 19, 2020March 23, 2020 by mali

Efficiency is very important in every task. Efficient processes, procedures lead to time saving, which leads to either saving money or additional revenue. Automation in information technology has become an important skill and that is where Python seems to be shinning these days. Many network engineers are using Python to automate tasks and increase overall efficiency.

I do not have any programming background and not something I have indulged into in the past other than some small things with batch files, auto hot key, excel etc. Working on some recent projects made me realize that I need to become more efficient and learn some Python.

With that in mind I worked on my very first python script, it isn’t amazing but gets the job done and its my first step towards learning something new. Will be posting them here as a reference and to hopefully get some feedback and improve.

Script to log into Cisco WLC

I needed to do the following:

  • Log into a Cisco WLAN Controller
  • Execute commands and display in the terminal window
  • Execute commands and dump the output in the text file.

This code below is very basic and all it does is asks me the IP of the device, then logs in and displays the output of the command, in this case “show ap summary”.

from netmiko import ConnectHandler
ipaddr = input('IP:''')

net_connect =  ConnectHandler(ip = ipaddr,
                        port = 22,
                        username = 'admin',
                        password = 'mypassword',
                        device_type = 'cisco_wlc_ssh')

net_connect.find_prompt()
'(Cisco Controller) >'
output = net_connect.send_command('show ap summary')
print(output)
net_connect.disconnect()

Next code goes a little further and runs two commands and saves the output to a text file.

#This will dump AP summary and CDP information for all APs in a text file

from netmiko import ConnectHandler
import sys

def sh_ap_sumcdp():

	ipaddr = input('IP:''')
	net_connect =  ConnectHandler(ip = ipaddr,port = 22,username = 'admin',password = 'mypassword',device_type = 'cisco_wlc_ssh')
	net_connect.find_prompt()
	'(Cisco Controller) >'
	cmd = 'show ap summary'
	output = net_connect.send_command(cmd)
	sys.stdout = open('wlccon.txt', 'w')
	print(output)
	cmd = 'show ap cdp ne all'
	output = net_connect.send_command(cmd)
	print(output)

sh_ap_sumcdp()

Currently I am not able to make this work over VPN connections for some reason. And it seems to fail even locally if I am using a VPN for some reason. There is much more to learn and improve but this is just a first step. I am certain there are better ways to do this, so please feel free to leave feedback or any tips so that I can improve.

I used the following sources as a starting point and get some inspiration from.

  • How to connect to a Cisco WLC – Thanks François.
  • Python for Network Engineers
Category: Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • CLI to UI – Nile Guest APIs
  • Nile Secure Guest – Configuration and Use Case
  • WLAN Pros Toolbox
  • Nile does NAC – Configuring Trust Engine
  • WLAN Validator

Tags

#MFD9 - Juniper Presents AP W318 arista Arista AGNI Arista CV-CUE Arista Hospitality AP Arista NAC Arista presents at MFD9 Arista wall plate AP Arista WIPS Arista WPA3 UPSK Aruba Central Automation CWAP 403 EAP Format MAC Addresses Hamina Network Planner Juniper Mist show cloud-native NAC Juniper SRX300 Marvis MFD8 MFD9 MistAI Mist MPSK Mist Premium Analytics Mist Wireless NaaS Networking Field Day NFD32 Nile APIs NileNav Nile Secure Nile Wi-Fi Tech Field Day Troubleshooting with Marvis Troubleshooting with Mist Troubleshooting with Mist AI Troubleshooting with Wireshark True NaaS Wireless Adjuster Wireless Adjuster Level II Wireless troubleshooting WLPC wlpc2023 Wyebot

Tech Blogs

  • CCNA Wireless
  • Cisco Full Bars
  • Packet Life
  • The ASCII Construct
  • Juniper Port Checker
  • Bad-Fi
  • Gjermund Raaen
  • Havilandweb
  • WiFiTodd
  • BadgerWiFi
  • WiFrizzy
  • Spectrum Chart

Recent Comments

  • Hiten Thakkar on PCAP I/O Graph Analyzer
  • mali on Deploying Nile Secure – My First NSB
  • Larry Farrish on Deploying Nile Secure – My First NSB
  • Courtney on Mist Access Point – CSV
  • ayoub chabrouk on Ubiquiti stealing the show at MFD11

Archives

  • August 2026
  • July 2026
  • March 2026
  • February 2026
  • December 2025
  • November 2025
  • October 2025
  • August 2025
  • May 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • November 2022
  • October 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • May 2021
  • April 2021
  • March 2021
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • April 2019
  • March 2019
  • November 2018
  • October 2018
  • September 2018
  • May 2018
  • January 2018
  • December 2017
  • August 2017
  • January 2017
  • September 2014
  • December 2013
  • October 2013
  • May 2013
  • August 2012
  • July 2012

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Categories

  • AeroHive
  • Arista
  • Arista
  • Aruba
  • Aruba
  • Aruba Central
  • BYoD
  • Certifications
  • Cisco
  • Cisco
  • Cisco EEM Scripting
  • Cisco Routing
  • Cisco Security
  • Cisco VoIP
  • Cisco VPN
  • Cisco Wireless
  • Conferences and Meetings
  • Design
  • Ekahau
  • General
  • Hamina
  • IoT, IIoT, OT
  • Juniper Security
  • Juniper Switching
  • Juniper/Mist
  • Linux
  • Microsoft
  • Mist
  • Mist Wireless
  • Nile
  • Nile Secure
  • Nile Wi-Fi
  • Programming/Automation
  • Python
  • Ruckus
  • Ruckus Wireless
  • Ruckus/Brocade
  • Ruckus/Brocade Scripting
  • Ruckus/Brocade Switching
  • Secure Guest Service
  • Security
  • Switching
  • Tools
  • Troubleshooting
  • Trust Engine
  • Uncategorized
  • Windows
  • Wireless
  • Wireless
  • WLAN Tools
© 2026 artofrf.com | Powered by Minimalist Blog WordPress Theme