Electronic Intelligence in Aviation

DIY for a Spy: Real-time Aircraft Monitoring without ADS-B receiver

Discover a simple technical solution for meeting your girlfriend at the airport at a specified time, even without using an ADS-B receiver.

Dmytro Sazonov
ILLUMINATION

--

ADS-B Exchange flights monitoring

As I explained in one of my previous articles, ‘No Such Agency’ and ‘The Machine’, there are components included in the global surveillance complex called ‘The Machine’ that give the government an opportunity to monitor different electronic activities, such as aircraft movement around the globe. This is referred to as ELINT (Electronic Intelligence). Today, we will discuss one of the approaches for our private mission — to help us meet our spouse at Frankfurt Airport (FRA) at a certain time.

This article aimed to demonstrate that you can utilize ELINT for personal purposes without even special permission for this data. In today’s digital age, a vast amount of information is fully accessible and open for use by anyone, anywhere. Specialized knowledge or access is often unnecessary to monitor a vast amount of activities. This gives our favorite ‘The Machine’ an opportunity to collect and analyze a huge amount of data with ease.

ADVERTISEMENT: If you or someone you know is interested in collaborating with an expert in Low code, AI and Chatbot development, my friends from cosmith.io offer top-notch services for development and integrations.

Today, one of these approaches will be employed to achieve your goal — meeting your girlfriend at the airport at a certain time.

Mission

To enhance our mission’s effectiveness, we will involve a few key players: a field agentyou — who will act as an operative at the airport, coordinating the meeting with your girl. The second player is a computer program with access to aviation infrastructure, which will monitor the real-time arrival of your girlfriend’s Emirates flight from DXB to FRA.

  • Legend: imagine your girlfriend is a remarkable woman who values punctuality and appreciates your attention and support during her crucial operations. As a CIA agent in the Middle East, she often returns exhausted from the business trip to Dubai. The last time you were late to meet her at the airport, it led to an argument. You work for Deutsche Bank as a software engineer, and managing time can be challenging for you. Therefore, you’ve decided to employ software to assist you this time.
  • This means: that you decided to focus on tracking her flight EK47 trail activities rather than relying on the scheduled arrival time, as the flight can be delayed. You have chosen to monitor the aircraft’s real-time information using aviation equipment like an ADS-B receiver.
  • Options: you have a few options to achieve this goal, either listen to 1090 MHz using an RTL-SDR device or install an ADS-B receiver in a suitable manner to capture the signal. Alternatively, you can leverage existing aviation infrastructure by connecting to one of the ADS-B data providers like ADS-B Exchange or FlightRadar24.
  • Setup: to simplify this task, the approach will involve connecting to the FlightRadar24 API to retrieve real-time data about the current position (latitude and longitude) and ground speed (in knots) of flight EK47.
  • Mission: based on your calculations, to be on time at the airport requires departing from your location 60 min beforehand. Therefore, you will install the script to GCP (Google Cloud Platform), which will be configured to remind you 60 min in advance when the aircraft is within the time of arrival, signaling the need to start your journey.

Now, because the objectives are established, we can begin the mission if you agree to accept it, of course.

Prerequisites

Firstly, we need to prepare the environment, which will include three essential components:

  • Create the Telegram-Bot and Channel to receive the messages in a convenient way. How to do that, you can read in the prerequisites section of another my articles;
  • Retrieve the details regarding your girlfriend’s flight from FlightRadar24 by searching for her flight EK47. As shown in the picture below, you’ll need to find the registration number (A6-EVB) for the flight, and the airport of arrival (FRA);
FlightRadar24 real-time aircraft monitoring
  • Set up the software infrastructure for the GCP web function and job, scheduled to execute the script every 1 min. Read further in this article on how to do that easily.

As everything is clear, let’s set up the dependencies.

Installation

In our solution, we’ll utilize three Python packages: ‘geopy’ for calculating the distance between the aircraft and the airport, ‘airportsdata’ for obtaining the actual coordinates for the airport, and ‘FlightRadar24API’ for fetching real-time flight information from the ADS-B infrastructure.

geopy
airportsdata
FlightRadarAPI

As we’ve decided to use GCP for script installation, to correctly install these packages, everything you need will be contained within these three lines in the ‘requirements.txt’ file in the GCP web function.

Imports

We need to import the following list of packages, which will be used further in our program.

import requests
import airportsdata

from geopy.distance import geodesic
from datetime import datetime, timedelta
from FlightRadar24 import FlightRadar24API

Here is what we have so far:

  1. requests: we will utilize it for making HTTP requests to Telegram Bot, interacting with its API;
  2. airportsdata: retrieves airport coordinates by its IATA airport code;
  3. geopy.distance.geodesic: calculates the geodesic distance between geographic locations. In our case, between the current position of the aircraft and the airport;
  4. datetime: will be utilized for dates and times manipulations;
  5. FlightRadar24: interfaces for the FlightRadar24 API. It will be used in our script for fetching real-time flight data.

Sending messages

To remind you to meet your girlfriend at the airport, we will utilize a Telegram Bot and Channel. Our script will send a message once the aircraft is within 1 hour from the airport.

TELEGRAM_URL = 'https://api.telegram.org'
TELEGRAM_BOT_ID = 'bot5603010001:III_xNHA14A9xznXjjcUD98GXT-A5zAAxzX' # Your bot
TELEGRAM_CHAT_ID = '-1008101011052' # Your airport reminder channel

def send_message(message):
response = requests.post(
f'{TELEGRAM_URL}/{TELEGRAM_BOT_ID}/sendMessage?chat_id={TELEGRAM_CHAT_ID}&parse_mode=Markdown&text={message}')
return response

As shown in the listing above, you will need to generate and replace the appropriate TELEGRAM_BOT_ID and TELEGRAM_CHAT_ID with your own settings. Detailed instructions on how to do that are provided in the ‘Prerequisites’ section of another article.

Getting airport coordinates

The get_airport_coordinates function retrieves the latitude and longitude of an airport using its IATA code. It first loads airport data, checks if the code exists among the airport's list, and returns the coordinates, rounded to three decimal places. If the code is invalid, it returns None.

def get_airport_coordinates(iata_code):
airports = airportsdata.load('IATA')
if iata_code in airports:
airport = airports[iata_code]
lat = round(airport['lat'], 3)
lon = round(airport['lon'], 3)
return (lat, lon)
else:
return None

We use this function in our main script to obtain the airport location for the IATA codeFRA’, which corresponds to Frankfurt Airport.

Getting aircraft trail details

The get_aircraft_trail_details function retrieves real-time details of an aircraft's trail using its registration number (A6-EVB). It uses the FlightRadar24 API, fetches flight data, and extracts information such as current geo-position, speed (in knots), and flight number (EK47).

def get_aircraft_trail_details(reg):
fr_api = FlightRadar24API()
flights = fr_api.get_flights(registration=reg)
if flights:
flight_details = fr_api.get_flight_details(flights[0])
if flight_details:
aircraft_lat = round(flight_details['trail'][0]['lat'], 3)
aircraft_lon = round(flight_details['trail'][0]['lng'], 3)
aircraft_kts = int(flight_details['trail'][0]['spd'])
flight_num = flight_details['identification']['number']['default']
return (aircraft_lat, aircraft_lon, aircraft_kts, flight_num)
return None

This FlightRadar24 API enables aircraft monitoring by broadcasting data obtained from ADS-B ground receivers tracking the aircraft’s trail.

Calculating time of arrival

The calculate_time_to_reach_airport function estimates the time needed for an aircraft to reach the airport based on its current coordinates and groundspeed (in knots), returning the number of minutes to arrival.

The get_flight_eta the function retrieves the estimated (by the crew in the aircraft) time of arrival for a specific flight based on its registration number (A6-EVB), also minutes before arrival.

def calculate_time_to_reach_airport(airport_coords, aircraft_coords, groundspeed_kts):
groundspeed_kmh = groundspeed_kts * 1.852
distance_km = geodesic(airport_coords, aircraft_coords).kilometers
time_minutes = int(distance_km / groundspeed_kmh * 60)
return time_minutes

def get_flight_eta(reg):
eta = 0
fr_api = FlightRadar24API()
flights = fr_api.get_flights(registration=reg)
if flights:
flight_details = fr_api.get_flight_details(flights[0])
if flight_details:
arrival_time = datetime.fromtimestamp(flight_details['time']['estimated']['arrival'])
current_time = datetime.now()
time_difference = (arrival_time - current_time).total_seconds() / 60
eta = time_difference
return int(eta)

As shown in the picture below, the estimated time of arrival provided by the crew in the cockpit is presented in the JSON response from the API.

JSON response

We utilize the estimated time of arrival as additional data and do not rely on it entirely. You will see this approach in the main function, ‘Airport Reminder’, further ahead.

Airport reminder

Let’s explore the main function aircraft_approaches_airport_go, which executes the core logic of our spy application by receiving a request from the GCP Scheduler. The request includes JSON data containing the IATA code of the airport (airport_iata_code), the registration number of the aircraft (aircraft_reg), and the number of minutes (remind_me) before which a reminder message will be sent to you.

Right after variable initialization, the function proceeds to retrieve the coordinates of the airport using the provided IATA code, and the detailed trail information for the aircraft using its reg-number. It calculates the estimated time of arrival (ETA) for the aircraft using both the aircraft’s speed (in knots) and the distance to the airport.

Additionally, it fetches the estimated time of arrival (ETA) provided by the crew members using the get_flight_eta function.

def aircraft_approaches_airport_go(request):
request_json = request.get_json()

airport_iata_code = request_json.get('airport_iata_code')
aircraft_reg = request_json.get('aircraft_reg')
remind_me = int(request_json.get('remind_me'))

airport_coords = get_airport_coordinates(airport_iata_code)
if airport_coords:
print(f'{airport_iata_code} airport coordinates: {airport_coords}')

acrd = get_aircraft_trail_details(aircraft_reg)
if acrd:
print(f'Trail details for {aircraft_reg}: {acrd}')

minutes = calculate_time_to_reach_airport(airport_coords, (acrd[0], acrd[1]), acrd[2])
print(f'Calculated time of arrival to {airport_iata_code} for flight {acrd[3]}: {minutes} min.')

minutes_eta = get_flight_eta(aircraft_reg)
if minutes_eta > 0:
print(f'Estimated time of arrival to {airport_iata_code} for flight {acrd[3]}: {minutes_eta} min.')

average_estimation = int((minutes + minutes_eta) / 2)
print(f'Average ETA for flight {acrd[3]}: {average_estimation} min.')

if remind_me >= average_estimation:
print('You have to go....')
message = f'*AIRPORT REMINDER*: Estimated time of arrival' + \
f' to *{airport_iata_code}* for flight *{acrd[3]}* is less' + \
f' than {average_estimation} min. ' + \
f'\n\t_You have to go to the airport to pick up your girlfriend in time!_'
send_message(message)

return f'Airport reminder: DONE!'

Afterward, the function computes the average ETA by averaging the calculated ETA and the fetched ETA. If the reminder time is greater than or equal to the average ETA, it sends a reminder message to remind you to go to the airport.

Hurry up if you received the message!

GCP Function and Scheduler

If you’ve reached this section, I assume you are capable of creating Google Cloud Functions and scheduled jobs. If not, you can look at an example in another one of my articles here.

After reading that article, you’ll find it easy to create your own scheduler ‘Airport-reminder-launcher’ and configure the ‘Airport-reminder’ function, the settings for which is illustrated in the picture below.

JSON parameters

I want to emphasize that you will need to set up this section with the IATA code (airport_iata_code) set to 'FRA', the aircraft registration number (aircraft_reg) set to 'A6-EVB', and the number of minutes (remind_me) needed for you to reach the airport. I've used 60 minutes, but you can calculate your own amount based on the distance from the airport and traffic conditions in your city.

Outcome

Great, if you follow everything that I explained in this article, you will receive a Telegram message similar to the one displayed in the picture below. When the aircraft is appeared in 60 minutes zone before arrival you will receive such messages every one minute.

Airport reminder Telegram-channel

It’s a friendly reminder to start your journey to the airport. Otherwise, you may remember the arguments you had last time with your lovely girlfriend, who is actually Supergirl.

[Super girls don’t cry…, super girls just fly]

With such trivial techniques and everything we did in this experiment, I believe you will be on time at the airport, ready to meet her :)

Photo by Tim Dennert on Unsplash

X-Files

To try these scripts on your end, you will need to download and learn from the source code listed below.

Get in touch

If you have any questions about the concepts discussed in this article or any other ideas, don’t hesitate to reach out on Twitter.

Twitter: https://twitter.com/dmytro_sazonov

The best expert in Low code, AI and Chatbot development

--

--

Dmytro Sazonov
ILLUMINATION

Blockchain enthusiast and artificial intelligence researcher. I believe with these tools we will build better tomorrow :)