Skip to main content

Python Team Awareness Kit (PyTAK) Module

Project description

Support Development: Sponsor this project on GitHub sponsors.

Python Team Awareness Kit (PyTAK)

Screenshot of ADS-B PLI in ATAK.

PyTAK is a Python Module for creating TAK clients, servers & gateways and includes classes for handling Cursor-on-Target (CoT) & non-CoT data, as well as functions for serializing CoT data.

PyTAK supports the following I/O & network protocols:

  • TCP Unicast: tcp://host:port

  • TLS Unicast: tls://host:port (see TLS Support section below)

  • UDP Unicast: udp://host:port

  • UDP Broadcast: udp+broadcast://network:port

  • UDP Multicast: udp://group:port

  • stdout or stderr: log://stdout or log://stderr

PyTAK has been tested and is compatible with many situational awareness & common operating picture systems (SA & COP).

Servers:

Clients:

PyTAK is used by many CoT & TAK gateways:

  • aiscot: Automatic Identification System (AIS) to COT Gateway. Transforms marine AIS position messages to COT PLI Events.

  • adsbcot: Automatic Dependent Surveillance-Broadcast (ADS-B) to COT Gateway. Transforms aircraft ADS-B position messages to COT PLI Events.

  • adsbxcot: ADS-B Exchange to COT Gateway. Transforms aircraft ADS-B position messages to COT PLI Events.

  • stratuxcot: Stratux ADS-B to COT Gateway. Transforms aircraft ADS-B position messages to COT PLI Events.

  • aprscot: Automatic Packet Reporting System (APRS) to COT Gateway. Transforms APRS position messages to COT PLI Events.

  • spotcot: Globalstar SPOT to COT Gateway. Transforms Spot satellite position messages to COT PLI Events.

  • inrcot: Garmin inReach to COT Gateway. Transforms inReach satellite position messages to COT PLI Events.

  • zellocot: ZelloWork to COT Gateway. Transforms ZelloWork user locations to COT PLI Events.

Support Development

Support Development: Sponsor this project on GitHub sponsors. Support Development: Buy me a coffee! Support Development: Buy Me a Coffee at ko-fi.com

Tech Support: Email support@undef.net or Signal/WhatsApp: +1-310-621-9598

This tool has been developed for the Disaster Response, Public Safety and Frontline Healthcare community. This software is currently provided at no-cost to users. Any contribution you can make to further this project’s development efforts is greatly appreciated.

Usage

The following Python 3.7+ code example creates a TAK Client that generates takPong CoT every 20 seconds, and sends them to a TAK Server at tcp://takserver.example.com:8087 (plain / clear TCP).

To run this example as-is, save the following code-block out to a file named example.py and run the command python3 example.py:

#!/usr/bin/env python3

import asyncio
import xml.etree.ElementTree as ET

from configparser import ConfigParser

import pytak


class MySerializer(pytak.QueueWorker):
    """
    Defines how you process or generate your Cursor-On-Target Events.
    From there it adds the COT Events to a queue for TX to a COT_URL.
    """

    async def handle_data(self, data):
        """
        Handles pre-COT data and serializes to COT Events, then puts on queue.
        """
        event = data
        await self.put_queue(event)

    async def run(self, number_of_iterations=-1):
        """
        Runs the loop for processing or generating pre-COT data.
        """
        while 1:
            data = tak_pong()
            await self.handle_data(data)
            await asyncio.sleep(20)


def tak_pong():
    """
    Generates a simple takPong COT Event.
    """
    root = ET.Element("event")
    root.set("version", "2.0")
    root.set("type", "t-x-d-d")
    root.set("uid", "takPong")
    root.set("how", "m-g")
    root.set("time", pytak.cot_time())
    root.set("start", pytak.cot_time())
    root.set("stale", pytak.cot_time(3600))
    return ET.tostring(root)


async def main():
    """
    The main definition of your program, sets config params and
    adds your serializer to the asyncio task list.
    """
    config = ConfigParser()
    config["mycottool"] = {"COT_URL": "tcp://takserver.example.com:8087"}
    config = config["mycottool"]

    # Initializes worker queues and tasks.
    clitool = pytak.CLITool(config)
    await clitool.setup()

    # Add your serializer to the asyncio task list.
    clitool.add_tasks(set([MySerializer(clitool.tx_queue, config)]))

    # Start all tasks.
    await clitool.run()


if __name__ == "__main__":
    asyncio.run(main())

Requirements

PyTAK requires Python 3.6 or above and WILL NOT work on Python versions below 3.6. It should run on almost any platform that supports Python 3.6+, including Linux, Windows, Raspberry Pi, Android, et al.

Installation

PyTAK is available as a Debian .deb package. This is the preferred method to install PyTAK:

$ wget https://github.com/ampledata/pytak/releases/latest/download/python3-pytak_latest_all.deb
$ sudo apt install -f ./python3-pytak_latest_all.deb

Alternative Installation

You can install from PyPI or from source. Both of these methods will require manual installation of additional libraries.

1a. Debian, Ubuntu, Raspberry Pi: Install LibFFI:

$ sudo apt update -y
$ sudo apt install libffi-dev

1b. RedHat, CentOS: Install LibFFI:

$ sudo yum install libffi-devel

2a. Install PyTAK from the Python Package Index:

$ python3 -m pip install pytak

2b. Install PyTAK from source:

$ git clone https://github.com/ampledata/pytak.git
$ cd pytak/
$ python3 setup.py install

Configuration Parameters

All configuration parameters can be specified either as environment variables or within an INI-style configuration file.

  • COT_URL: (optional) Destination for Cursor on Target messages. Default: udp://239.2.3.1:6969 (ATAK Multicast UDP Default)

  • DEBUG: (optional) Sets debug-level logging.

  • FTS_COMPAT: (optional) If set, implements random-sleep period to avoid FTS DoS protections.

  • PYTAK_SLEEP: (optional) If set, implements given sleep period between emitting CoT Events.

TLS Support

TLS Support for connections to TAK destinations is configured with two settings:

  1. Specify tls:// in the CoT Destination URL, for example: tls://takserver.example.com:8089

  2. Specify the TLS Cert and other configuration parameters.

Client Certificates, Client Key, CA Certificate & Key must be specified in PEM format.

N.B: Encrypted private keys are not supported and must be saved in clear-text: openssl rsa -in my_cert.key.pem -out my_cert-nopass.key.pem

Minimum TLS Configuration

  • PYTAK_TLS_CLIENT_CERT: PEM Public Key Certificate that the PyTAK-based client will use to connect.

Optional TLS Configuration

  • PYTAK_TLS_CLIENT_KEY: PEM Private Key for the associated PYTAK_TLS_CLIENT_CERT

  • PYTAK_TLS_DONT_VERIFY: Disable destination TLS Certificate Verification.

  • PYTAK_TLS_DONT_CHECK_HOSTNAME: Disable destination TLS Certificate Common Name (CN) Verification.

  • PYTAK_TLS_CLIENT_CAFILE: PEM CA trust store to use for remote TLS Verification.

  • PYTAK_TLS_CLIENT_CIPHERS: Colon (“:”) seperated list of TLS Cipher Suites.

For example, to send COT to a TAK Server listening for TLS connections on port 8089:

PYTAK_TLS_CLIENT_CERT=client.cert.pem
PYTAK_TLS_CLIENT_KEY=client.key.pem
COT_URL=tls://tak.example.com:8089

FreeTAKServer Support

FTS (Free TAK Server) has built-in anti-Denial-of-Service (DoS) support, which restricts the number of CoT Events a client can send to a listening TCP Port. Currently this FTS feature cannot be disabled or changed, so clients must meter their input speed.

To use a PyTAK-based client with FTS, set the FTS_COMPAT configuration parameter to True This will cause the PyTAK client to sleep a random number of seconds between transmitting CoT to a FTS server:

FTS_COMPAT = True

Alternatively you can specify a static sleep period by setting PYTAK_SLEEP to an integer number of seconds:

PYTAK_SLEEP = 3

Source

Github: https://github.com/ampledata/pytak

Author

Greg Albrecht W2GMD oss@undef.net

https://ampledata.org/

License

Copyright 2022 Greg Albrecht <oss@undef.net>

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

  • asyncio_dgram is licensed under the MIT License, see pytak/asyncio_dgram/LICENSE for details.

Style

Python Black, otherwise Google, then PEP-8.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytak-5.4.0.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytak-5.4.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file pytak-5.4.0.tar.gz.

File metadata

  • Download URL: pytak-5.4.0.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for pytak-5.4.0.tar.gz
Algorithm Hash digest
SHA256 39e9154d2f8856a1b77bfa815ad86e41a27c578d52f88ef3603016739a94a61b
MD5 a256a73028dbeaa242e854cfeea1721f
BLAKE2b-256 30e5684b16ef72513e900d96f2b6775a63f1a26c98f23f80d89e34f0a1550b86

See more details on using hashes here.

File details

Details for the file pytak-5.4.0-py3-none-any.whl.

File metadata

  • Download URL: pytak-5.4.0-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for pytak-5.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6303dc9abfe3949b769efc27ffc7d3a6f29f2374e74d8c0caca9e9eb9966a4c7
MD5 e051ef03db977e6a568aa4c5940a4ac7
BLAKE2b-256 04def54c4544ed5f84845c359df0e7fed08c67579dd0a0bb9124a673e65e0e4a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page