An (unofficial) Rust library for querying db-ip.com data

Overview

db_ip

An (unofficial) library for querying db-ip.com CSV databases in safe Rust.

This library is not affiliated with or endorsed by db-ip.com.

Be advised that, by using this library with lite databases (such as the one downloaded automatically in the build step), you are subject to license terms (requiring attribution).

Examples

You can use DbIpDatabase to get the actual two-letter country code. The country code database will be embedded, in a compressed form, in your Rust binary.

use db_ip::{DbIpDatabase, CountryCode, include_country_code_database};

// Embed compressed database in binary:
let db = include_country_code_database!();
// Or, load it from the filesystem:
// let db = DbIpDatabase::
   
    ::from_csv_file("country_or_city_data.csv").unwrap();
   

assert_eq!(
    db.get(&"192.99.174.0".parse().unwrap()),
    Some(CountryCode::from_str("US").unwrap())
);

You can use DbIpDatabase , enabled by the region feature, to gain a broad understanding of an IP's location. Since there are fewer possibilities, this takes less binary size and RAM.

use db_ip::{DbIpDatabase, Region, include_region_database};

// Embed compressed database in binary:
let db = include_region_database!();
// Or, load it from the filesystem:
// let db = DbIpDatabase::
   
    ::from_csv_file("country_or_city_data.csv").unwrap();
   

assert_eq!(
    db.get(&"192.99.174.0".parse().unwrap()),
    Some(Region::NorthAmerica)
);

Finally, you can implement IpData yourself, to store any other type of data that can be derived from Country or City data records.

Downloading IP Geolocation Data

You can manually download the actual ip geolocation data (in CSV format) in one of the following ways.

  • Use the default download-country-lite feature, which attempts to download the most recent available Country lite data
  • Country data lite (recommended)
  • City data lite (larger file size)
  • You may also try the paid database versions for better accuracy, but they have not been tested with this crate

Once you have downloaded a CSV file, use the csv feature to load it.

Features

The raw csv data takes a while to parse, even in release mode. You may use the serde feature to create and load a serialized version.

You can selectively disable the ipv4 and ipv6 features, depending on your needs. Both are on by default.

Lookups are relatively speedy, taking less than 100ns in release mode.

Limitations

If you want easier access to data other than CountryCode and Region, create an issue.

The db-ip.com API is not currently supported, so it is difficult to keep the database up to date.

License

Code licensed under either of

at your option.

Bundled/downloaded geolocation data licensed under LICENSE-DBIP.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

You might also like...
A dead-simple tool for working with data in Kafka
A dead-simple tool for working with data in Kafka

ktool - a tool for Kafka ktool is a dead-simple tool for working with data in Kafka: Copy partitions / topics to disk Replay messages Inspect message

A highly modular Bitcoin Lightning library written in Rust. Its Rust-Lightning, not Rusty's Lightning!

Rust-Lightning is a Bitcoin Lightning library written in Rust. The main crate, lightning, does not handle networking, persistence, or any other I/O. Thus, it is runtime-agnostic, but users must implement basic networking logic, chain interactions, and disk storage. More information is available in the About section.

Rust library that can be reset if you think it's slow

GoodbyeKT Rust library that can be reset if you think it's slow

Notion Offical API client library for rust

Notion API client library for rust.

Rust library for program synthesis of string transformations from input-output examples 🔮

Synox implements program synthesis of string transformations from input-output examples. Perhaps the most well-known use of string program synthesis in end-user programs is the Flash Fill feature in Excel. These string transformations are learned from input-output examples.

SE3 Rust library for Robotics

Algebraic Robots A small Rust Library for SE3 Supported: Twist Screw SE3 Group se3 algebra Adjoint SE3 Twist Chains Wrenches Future plans: Jacobians V

Rust library for emulating RISC-V rv32imac

This library can execute instructions against any memory and register file that implements the required primitives in the traits lib_rv32::traits::{Memory, RegisterFile}. This is to encourage usage with whatever frontend you desire.

Yet another ROS2 client library written in Rust
Yet another ROS2 client library written in Rust

RclRust Target CI Status Document Foxy (Ubuntu 20.04) Introduction This is yet another ROS2 client library written in Rust. I have implemented it inde

A boiler plate code to create dynamic link library in rust.

🔭 rust-dll-bp This is a boiler plate code that will be generated as a dll binary. I personally cache this here for me but if you're intend to create

Comments
  • I need some clarifications about `include_country_code_database!()`

    I need some clarifications about `include_country_code_database!()`

    Hi! Thank you for having created the db_ip crate!

    I would like to use it in my project and I wanted some clarifications.

    Which database is the instruction let db = include_country_code_database!() loading? Do I need to serialize it? How can the serde feature be used? Is there any difference with the db I can download from dp-ip.com?

    opened by GyulyVGC 6
  • docs.rs not able to build docs

    docs.rs not able to build docs

    Seems that docs.rs is not beeing able to build the docs, the doc generating process has constraints that probably are not beeing met by this crate.

    It would be nice if you can generate and post the docs for this crate yourself.

    If you are insterested, let me know and I can create a static server to host the docs, probably in some provider like netlify or so.

    opened by ramiroaisen 2
  • AS lite db availability

    AS lite db availability

    It would be nice to have a macro that works as the already present macro to load countries, but for querying autonomous system db.

    It could be of interest to add the same support in terms of automatic fetching and compression of the latest db version as well, as already done for countries.

    opened by GyulyVGC 2
Owner
Finn Bear
Squirrel!
Finn Bear
Unofficial Bitwarden compatible server written in Rust, formerly known as bitwarden_rs

Alternative implementation of the Bitwarden server API written in Rust and compatible with upstream Bitwarden clients*, perfect for self-hosted deploy

Daniel García 21.5k Jan 8, 2023
[Unofficial] Azure SDK for Rust

[Unofficial] Azure SDK for Rust This repository is for the development of the unofficial Azure SDK for Rust. It is unofficial because it is not yet su

Microsoft Azure 390 Dec 30, 2022
RusTTS is an unofficial Coqui TTS implementation

RusTTS RusTTS is an unofficial Coqui TTS implementation. Currently, only the YourTTS for VC has been implemented. So, feel free to contribute us to ma

Ho Kim 13 Sep 12, 2022
A library to access BGPKIT Broker API and enable searching for BGP data archive files over time from public available data sources.

BGPKIT Broker BGPKIT Broker is a online data API service that allows users to search for publicly available BGP archive files by time, collector, proj

BGPKIT 10 Nov 30, 2022
Uindex is a data store, for data that can be parsed as sentences in some context-free language.

Uindex - Universal index Uindex is a data store, for data that can be parsed as sentences in some context-free language.

Enrique Pérez Arnaud 3 Jul 20, 2021
RusQTTbom takes weather data from the Bureau of Meteorology (BOM) and publishes that data via MQTT messages.

RusQTTbom RusQTTbom collects weather data from the Bureau of Meterology (BOM) then publishes said data locally via MQTT messages. BOM weather data is

Athenars 7 Jan 13, 2023
NSE is a rust cli binary and library for extracting real-time data from National Stock Exchange (India)

NSE Check out the sister projects NsePython and SaveKiteEnctoken which are Python & Javascript libraries to use the NSE and Zerodha APIs respectively

Techfane Technologies 4 Nov 28, 2022
Showing how to deploy a Terra smart contract using Chainlink Data Feeds

Chainlink Terra Developing Requirements This demo requires the following components: Rust: rustup with cargo 1.44.1+. rustc and cargo 1.44.1+. Install

SmartContract 6 Aug 22, 2022
A tool using binrw to read FFXIV data files

last-legend-dob A tool using binrw to read FFXIV data files. Mainly made to harvest the music from the game files for personal consumption, since it t

Octavia Togami 2 Oct 10, 2022
sblade or switchblade it's a multitool in one capable of doing simple analysis with any type of data, attempting to speed up ethical hacking activities

sblade or switchblade it's a multitool in one capable of doing simple analysis with any type of data, attempting to speed up ethical hacking activities

Gabriel Correia 1 Dec 27, 2022