Python – Extract AP Pictures from an Ekahau Project

When I perform Wi-Fi validation or Wi-Fi assessments, I like to take pictures of the access points and document it later. I also save these pictures and provide them to the customer.

Lately, with the use of the Ekahau survey application on iPad, I have been attaching these pictures to an AP object on my Ekahau project files using the iPad application.

The task of saving these pictures manually can be very time consuming. So I decided to practise my Python skills and create a script that would do it for me.

DESCRIPTION

The script opens an Ekahau project, look for an access point object that has a picture attached to it. It then create a new directory and copy these AP pictures into the new directory. The image is renamed with the name of the AP you have in your Ekahau project.
If you have multiple floorplans in your project, the script will create one sub-directory per floor.

THE CODE

import argparse
import time
import zipfile
import json
import shutil
import pathlib
import os
 
 
 
def main():
"""
This function will extract the images located into the AP notes and rename them using the AP Name
"""
parser = argparse.ArgumentParser(description='Extract images located in the AP notes and rename them using the AP name')
parser.add_argument('file', metavar='esx_file', help='Ekahau project file')
args = parser.parse_args()
 
 
 
# Load & Unzip the Ekahau Project File
current_filename = pathlib.PurePath(args.file).stem
with zipfile.ZipFile(args.file,'r') as myzip:
myzip.extractall(current_filename)
 
 
 
# Load the notes.json file into the notes Dictionary
with myzip.open('notes.json') as json_file:
notes = json.load(json_file)
 
 
 
# Load the accessPoints.json file into the accessPoints dictionary
with myzip.open('accessPoints.json') as json_file:
accessPoints = json.load(json_file)
 
 
 
# Load the floorPlans.json file into the floorPlans dictionary
with myzip.open('floorPlans.json') as json_file:
floorPlans = json.load(json_file)
 
 
 
# Create a new directory to place the new image in
newpath = os.path.abspath(pathlib.PurePath()) + "/AP-Images"
if not os.path.exists(newpath):
os.makedirs(newpath)
 
 
 
# Create one sub directory per floor under the /AP-Images directrory
for floor in floorPlans['floorPlans']:
sub = newpath + '/' + floor['name']
if not os.path.exists(sub):
os.makedirs(sub)
 
 
 
# Move all the AP Images on this floor into the corresponding directory
for ap in accessPoints['accessPoints']:
if 'location' in ap.keys():
if ap['location']['floorPlanId'] == floor['id']:
if 'noteIds' in ap.keys():
for note in notes['notes']:
if note['id'] == ap['noteIds'][0] and len(note['imageIds']) > 0:
image_count = 1
for image in note['imageIds']:
image_full_path = os.getcwd() + '/' + current_filename + '/image-' + image
if len(note['imageIds']) > 1:
dst = newpath + '/' + floor['name'] + '/'+ ap['name'] + '-' + str(image_count) + '.png'
else:
dst = newpath + '/' + floor['name'] + '/'+ ap['name'] + '.png'
shutil.copy(image_full_path, dst)
image_count += 1
 
 
 
# Clean Up
shutil.rmtree(current_filename)
 
 
 
if __name__ == "__main__":
start_time = time.time()
print('** Extracting AP picture notes...')
main()
run_time = time.time() - start_time
print("** Time to run: %s sec" % round(run_time,2))

USAGE

Simply launch the script specifying the name of the Ekahau project:
Feel free to use the script at your own risk 🙂
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments