Tag Archives: Python

Programmatically obtain a phone’s ESN

Bitpim is an open-source program that allows a user to manipulate data on a CDMA handset, including the phone book, wallpapers, ringtones, and in some cases, the filesystem. While poking around the application’s source, which is written in python, I found a great class that provides a quick way to access the phone’s manufacturer, ESN, and firmware revision. Yes, this information is available through a small set of keystrokes on CDMA handsets, but I have often found cases where I would still prefer to provide an app to a user and have it do all the dirty work.

The class is called “phone_detect.py” and it’s located under the /src/ in the source tree. All that it really does is act as a wrapper for the AT commands that are necessary to switch the phone into the correct mode and also to ask the phone for it’s configuration info. You can get a good understanding of what it’s doing by following the calls to __get_esn(). There are plenty of references available online that show the full range of AT commands that phones respond to.

To play with the class, you’ll need to get an install python. In addition to python, you will also need pySerial in order to interface with your serial port. Once you have your handset connected to your computer you can call use the class directly by calling DetectPhone().detect(). There’s an example of using this call in setphone_wizard.py if you need one.