Skip to main content

criminalip.ctidb reader

Project description

Description

This is a Python module for reading CTI DB files.

CTI DB is a binary file format that stores data indexed by IP address subnets (IPv4 only).

Installation

To install ctidb, type:

$ pip install ctidb

If you are not able to use pip, you may also use easy_install from the source directory:

$ easy_install .

Usage

To use this module, you must first download or create a CTI DB file.

After you have obtained a database and imported the module, call CCtiReader with a path, to the database as the first argument. Optionally, you may pass a mode as the second argument. The modes are exported from ctidb. Valid modes are:

  • MODE_MEMORY - load database into memory. Pure Python.

  • MODE_AUTO - Default.

NOTE: To look up an IP address, use the get method on this object. The method will return the corresponding values for the IP address from the database (e.g., a dictionary for GeoIP2/GeoLite2 databases). If the database does not contain a record for that IP address, the method will return None.

If you wish to also retrieve the prefix length for the record, use the get_with_prefix_len method. This returns a tuple containing the record followed by the network prefix length associated with the record.

Example

>>> import ctidb
>>>
>>> with ctidb.CCtiReader('criminalip.ctidb') as reader:
>>>
>>>     reader.get('152.216.7.110')
{'country': ... }
>>>
>>>     reader.get_with_prefix_len('152.216.7.110')
({'country': ... }, 24)

Exceptions

The module will return an InvalidDatabaseError if the database is corrupt or otherwise invalid. A ValueError will be thrown if you look up an invalid IP address or an IPv6 address in an IPv4 database.

Requirements

This code requires Python 3.6+. Older versions are not supported.

Versioning

Support

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

ctidb-0.0.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

ctidb-0.0.2-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file ctidb-0.0.2.tar.gz.

File metadata

  • Download URL: ctidb-0.0.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.9

File hashes

Hashes for ctidb-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f0719441887a9740a7a0f83466fb665417539e043b571baf989c00c440ab6e4d
MD5 40075cc0651515823d72b3a637d32b86
BLAKE2b-256 5cc959b569c036c984cd874d560d3b475d32afca7406e62aa9d8f3eabe293843

See more details on using hashes here.

File details

Details for the file ctidb-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ctidb-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.9

File hashes

Hashes for ctidb-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1d5e6e7b4ba309d329fec463439179c273868dbbba3636da3b391f2d1e093dd5
MD5 c94007406f9d8f4a0ee565eafbdfebad
BLAKE2b-256 43e03ca7eff33995a1990d5c90276dc108ed45db58156955a56f50276d6f35a3

See more details on using hashes here.

Supported by

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