Browse By

Python Script to Login to Extension Mobility without PIN

Login to Cisco IP Phone remotely without knowing user’s PIN

In this article, we will learn how to login to Cisco IP Phone remotely without knowing user’s PIN. I have created a python script to do this activity. The script comes very handy and easy to use. This is very helpful when you have cluster migration or site migration or a new site build. You can remotely get the users logged into their IP Phone which will save a huge amount of time.

To perform the login, there are three files associated.

  1. EMLoginWithoutPIN.py – The EMLoginWithoutPIN.py file is actually the heart which contains all the program. All you need to do is modify the appEmProxyUser in the script. This
  2. Data.csv – This file contains all the data related to the users. You need to feed in the IP Address of the CUCM, Mac-Address of the user’s device and user’s CUCM user id.
  3. result.csv – This file will contain results once you execute the script, the results file will tell you whether the user was logged in or not.

Creating a Application User in CUCM

  • Login to CUCM
  • Navigate to User Management > Application User > Add New
  • Add the Application user name as “emlogin
  • Create a Password
  • Permission Information > Click on Add to access control group
  • Add “Standard EM Authentication Proxy Rights” rights to the group
  • Click on Save

uccollabing.com

Modifying the data.csv

  • Make sure that the headers are not modified in the data.csv file
  • Enter the IP Address of the Call Manager in Column A starting from 2nd Row in A Column.
  • Enter the Mac Address of the IP Phone in Column C starting from 2nd Row in B Column. Make sure you prefix SEP in the mac-address.
  • Enter the User ID of the user whom you want to get logged into the IP Phone starting from 2nd Row in C Column
  • Keep entering the details row wise without keeping any blank rows.
  • Save the file

uccollabing.com

Here is the Python script

###################################################
###################################################
## This python script is created by UC Collabing ##
###################################################
###################################################
from pydoc import resolve
from urllib import response
import requests
import pandas as pd
import re
import getpass
import xml.etree.ElementTree as ET

df = pd.read_csv('data.csv')

ipAddress = df['IP_Address']
deviceName = df['Device_Name']
userID = df['UserID']

f = open("result.csv", "w+")
f.write("IP_Address, Device_Name, UserID, Status")
f.write("\n")
f.close()

##############################
appEmProxyUser = "emlogin"   
##############################

appPw = getpass.getpass(prompt="Enter the EM Proxy User password: ") 


for ipAddress, deviceName, userID, in zip(ipAddress, deviceName, userID):
    result = []
    uri = "http://" + ipAddress + ":8080/emservice/EMServiceServlet"
    headers = {"Content-Type": "application/x-www-form-urlencoded"}

    param = """<request>
                <appInfo>
        			<appID>"""+appEmProxyUser+"""</appID>
                	<appCertificate>"""+appPw+"""</appCertificate>
                </appInfo>
                <login>
                    <deviceName>"""+deviceName+"""</deviceName>
                    <userID>"""+str(userID)+"""</userID>
                </login>
            </request>"""

    r = requests.post(uri, data={"xml":param},headers=headers)
    XMLDoc=ET.fromstring(r.content)
    try:
        resPattern=XMLDoc.find(".//error").text
        #resPattern = resPattern.splitlines()
        resPattern = resPattern.rstrip("\n")
        #print(ET.tostring(XMLDoc, encoding='utf8').decode('utf8'))
        print(resPattern)
        
    except: 
        resPattern=XMLDoc.find(".//success").text
        #resPattern = resPattern.splitlines()
        #resPattern = resPattern.rstrip("\n")
        #print(ET.tostring(XMLDoc, encoding='utf8').decode('utf8'))
        resPattern = "Success"
        print(resPattern)

    result.append([ipAddress, deviceName, userID, resPattern])

    for i in result:
        i = ", ".join('%s' %id for id in i)      
        f = open("result.csv", "a")
        f.write(i)
        f.write("\n")
        f.close()

 

Reading the results.csv

  • Open the results.csv file
  • This will give you the results of the execution you made.
  • The results will appear in column D.

uccollabing.com

Here is the YouTube demo video.

 

Leave a Reply

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