Crate mhost

source ·
Expand description

mhost is a modern take on the classic host DNS lookup utility including an easy to use, and very fast Rust library.

The library is currently still in a PoC state. It works and the command line tool mhost already uses it. Nevertheless, I’m not satisfied with the design and architecture so it is still work in progress.

Unfortunately, this also means that the library totally lacks documentation. If you want to use the library in your own project, please be aware that the API might change. Even though documentation is missing, you can find fully working examples that might help to jump start you.

Please feel free to give me feedback in form of GitHub issues and I welcome any PRs.

§Example

Lookup A, AAAA, and TXT records for mhost.pustina.de using the local operating system’s nameservers as well as Google’s nameserver.

use mhost::nameserver::NameServerConfig;
use mhost::resolver::{MultiQuery, Resolver, ResolverConfig, ResolverGroup};
use mhost::resolver::lookup::Uniquify;
use mhost::statistics::Statistics;
use mhost::RecordType;
use std::net::SocketAddr;

// Create a `ResolverGroup` with operating system's nameservers; a `ResolverGroup`
// acts the same a single `Resolver` and allows to lookup records from multiple name servers.
let mut resolvers = ResolverGroup::from_system_config(Default::default())
     .await
     .expect("failed to create system resolvers");

// Create a Resolver for Google's DNS nameserver with UDP transport
let sock_addr: SocketAddr = "8.8.8.8:53".parse().unwrap();
let name_server_config = NameServerConfig::udp(sock_addr);
let config = ResolverConfig::new(name_server_config);
let google = Resolver::new(config, Default::default())
    .await
    .expect("Failed to create Google resolver");

// Add Google resolver to `ResolverGroup`
resolvers.add(google);

// Prepare a `MultiQuery`: Query multiple names and/or multiple record types at once
let query = MultiQuery::multi_record(
    "mhost.pustina.de",
    vec![RecordType::A, RecordType::AAAA, RecordType::TXT]
).expect("Failed to create query");

// Perform multi-lookup
let lookups = resolvers.lookup(query).await.expect("Failed to execute lookups");

// Print statistics about lookup results
println!("Statistics: {:#?}", lookups.statistics());

// Print all results
println!("Multi-Lookup results: {:#?}", lookups);

// Aggregate all A records
let a_records = lookups.a().unique().to_owned();
println!("A records: {:#?}", a_records);

Re-exports§

Modules§

  • mhost command line app to query, discover and lint DNS.
  • Compute diffs between sets of various record types to look for changes, deviations etc.
  • Main error type of this library.
  • Compute run time estimates for various queries.
  • Name servers are the basic abstraction for DNS servers configuration.
  • A resolver uses name servers configuration to resolve queries.
  • Resources like records and record types that are used to communicate queries and results.
  • Supporting services to download name server lists and query WHOIS information for IP subnets.
  • Statistics module to compute statistical information on query results.
  • Read operating system configuration for DNS resolving, i.e. read /etc/resolv.conf.
  • Various helpers for serialization and concurrent execution control.

Structs§

Enums§

  • Represents a generic network range. This type can have two variants: the v4 and the v6 case.

Traits§

Type Aliases§