This project is a Rust application designed to check the geolocation of DNS addresses. It utilizes various Rust crates to parse configuration files, perform DNS queries, and check IP geolocations.
To get started with this project, clone the repository and ensure you have Rust and Cargo installed on your system.
Binary releases are available on crates.io. You can install the DNS Geolocation Checker using the following command:
cargo install dns-geolocation-checker
- Clone the repository:
git clone https://github.com/single9/dns-geolocation-checker.git
- Navigate to the project directory:
cd dns-geolocation-checker
- Build the project:
cargo build
The DNS Geolocation Checker supports the following feature flags:
ip-api
: Enables the IP Geolocation API provider.mmdb
: Enables the MaxMind GeoLite2 database provider.
To enable a feature flag, use the following command:
cargo build -F ip-api
To enable full features, use the following command:
cargo build -F full
You can configure the DNS Geolocation Checker by modifying the config.toml
file. The configuration file contains the following sections:
[test_subnets]
sg = { subnets = ["175.41.192.0/18"] }
us = { subnets = ["44.208.193.0/24"] }
[[domain]]
host = "www.example.com"
geo_routing = ["sg", "us"]
-
test_subnets
: Defines a section for testing subnets with geographical identifiers.sg
: A key representing Singapore, containing a list with a single subnet"175.41.192.0/18"
.us
: A key representing the United States, containing a list with a single subnet"44.208.193.0/24"
.
-
[[domain]]
: An array of domain configurations, allowing for multiple entries.host
: Specifies the domain name, here it is"www.example.com"
.geo_routing
: An array indicating which geographical subnet groups (sg
andus
) this domain is associated with for geo-routing purposes.
Put the file config.toml
in the configs
directory of the project. Or you can specify the path to the configuration file using the CONFIG_PATH
environment variable when running the application.
This is the default IP geolocation provider.
If you want to use the MaxMind GeoLite2 database, you need to download the database from the MaxMind website. After downloading the database, you need to specify the path to the database in the config.toml
file:
ip_geo_provider = "mmdb"
# Set the path to the MMDB file
# Default: "./mmdb/GeoLite2-City.mmdb"
mmdb_path = "/path/to/GeoLite2-City.mmdb"
The default path is ./mmdb/GeoLite2-City.mmdb
.
The IP Geolocation API is a free service that provides geolocation information for IP addresses.
If you want to use the IP Geolocation API service, you need to specify the provider in the config.toml
file:
ip_geo_provider = "ip-api"
To run the DNS Geolocation Checker, use the following command:
cargo run --bin dns-geo-checker
When you run the DNS Geolocation Checker, it will query the DNS records for each domain and check the geolocation of the IP addresses returned. If the IP address falls within one of the subnets specified in the test_subnets
section, the geolocation will be considered a match.
To build the project, use the following command:
cargo build
You can find the compiled binary in the target/release
directory.
To run the tests for this project, execute:
cargo test --verbose
- CLI mode
- Support multiple IP geolocation providers
- Support IPv6 addresses
- Map IP addresses to geographical locations
This project is licensed under the MIT License - see the LICENSE file for details.