Building Cisco IP Phone Services (Part 3) : Coding with Python & XML

In Part 1 and Part 2 of this series, we went through the the inner working of a Cisco IP phone’s service and the payload that gets sent along with the execution request.

In this concluding third part of the series, we will be putting whatever we have learned in the last couple of posts into a code that can give us some tangible output. We will be writing the code in Python. So, it is assumed that you have some cursory understanding of Functions, Variables, payload formats like XML etc. If you want to download the code straight away then please click on point# 7 below.

  1. Use Case
  2. Declaring user credentials
  3. Preparing the payload
  4. Sending a request to the phone
  5. Combining the phone’s IP and payload
  6. Asking for the phone’s IP
  7. Github Repository

Use Case

Objective : We will be working on the same use case we went through in the last post. The objective is to reset security settings on a 7841 model Cisco phone.


Declaring user credentials

In order to execute the use case remotely, you need to have a User Profile in CUCM that has necessary permissions to control the phone. In other words, you need to have the phone added to the “Controlled Devices” section of the user profile and then supply the same user’s ID/password in the code.


Preparing the payload

Here, we are creating multiple functions and returning the XML payload that we discussed in Part 2. We are doing it this way by creating different functions for each payload and then calling them at a later stage, in order to adhere to the good coding practices. You can, of course, combine everything into one statement while sending a POST request to the phone but that wouldn’t be a very wise choice, unless you want to spend a long time trying to sort it out while simultaneously pulling your hair & cursing everyone around ๐Ÿ™‚


Sending a request to the phone

Here, we are sending a request to the phone’s HTTP server. The payload that will be sent along with this request will is explained in the next screenshot.


Combining the phone’s IP and payload

Here, we are calling the “Connect” function that we built in the previous screenshot and passing 2 critical parameters (Phone’s IP address and the payload) within it. The payload sequence mentioned here (Physical keys – 5, 4, 4, 4 and Softkey 2) were defined earlier in step 1


Asking for the phone’s IP


Github Repository

If you want to download this code sample and customize it for your own specific production environment, then head over to the following link

https://github.com/simranjit-uc/Cisco-ITL-Reset


I hope this three part series was helpful in demonstrating the functionality, usage & real world application of a phone service on a Cisco IP phone. This shows how we can go beyond, what is natively offered to us through CUCM/Phone’s GUI/CLI and work directly with the phone’s firmware through a different path and build our own custom web services.

Please feel free to drop your feedback/suggestions, if any. Happy Learnings!!

Letโ€™s connect on LinkedIn