Skip to content

yaslam-dev/dns-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DNS-Rust

A simple and fast DNS query tool written in pure Rust with no unsafe code.

Features

  • πŸ” Query various DNS record types: A, AAAA, NS, CNAME, MX
  • πŸ“ Detailed output: Shows complete DNS response information
  • 🌐 Custom DNS servers: Query any DNS server
  • βœ… Thoroughly tested: Comprehensive unit test coverage

Installation

From Source

  1. Make sure you have Rust installed. If not, install it from rustup.rs

  2. Clone this repository:

    git clone https://github.com/yaslam-dev/dns-rust.git
    cd dns-rust
  3. Build and install:

    cargo build --release
    cargo install --path .

    OR

  4. Install and Run

cargo test && cargo run -- cloudflare.com A

Using Cargo

cargo install dns-rust

Usage

Basic Usage

Query an A record for a domain:

dns-rust google.com A

Query different record types:

dns-rust example.com MX
dns-rust github.com AAAA
dns-rust google.com NS
dns-rust www.github.com CNAME

Using Custom DNS Server

Use a different DNS server (default is 8.8.8.8):

dns-rust google.com A --server 1.1.1.1
dns-rust example.com MX -s 9.9.9.9

Command Line Options

dns-rust [OPTIONS] <DOMAIN> <RECORD_TYPE>

Arguments:
  <DOMAIN>       The domain name to query
  <RECORD_TYPE>  The record type to query (A, AAAA, NS, CNAME, MX)

Options:
  -s, --server <SERVER>  DNS server to query (default: 8.8.8.8)
  -h, --help            Print help
  -V, --version         Print version

Supported Record Types

Type Description
A IPv4 address records
AAAA IPv6 address records
NS Name server records
CNAME Canonical name records
MX Mail exchange records

Examples

Query A Record

$ dns-rust google.com A
Querying 8.8.8.8:53 for A record of google.com

DNS Response:
=============
ID: 6666
Response: true
Authoritative: false
Truncated: false
Recursion Desired: true
Recursion Available: true
Result Code: NoError

Questions (1):
  A google.com

Answers (1):
  google.com                     287      A      142.250.80.78

Query MX Record

$ dns-rust gmail.com MX
Querying 8.8.8.8:53 for MX record of gmail.com

DNS Response:
=============
ID: 6666
Response: true
Authoritative: false
Truncated: false
Recursion Desired: true
Recursion Available: true
Result Code: NoError

Questions (1):
  MX gmail.com

Answers (5):
  gmail.com                      3599     MX     10 alt1.gmail-smtp-in.l.google.com
  gmail.com                      3599     MX     20 alt2.gmail-smtp-in.l.google.com
  gmail.com                      3599     MX     30 alt3.gmail-smtp-in.l.google.com
  gmail.com                      3599     MX     40 alt4.gmail-smtp-in.l.google.com
  gmail.com                      3599     MX     5 gmail-smtp-in.l.google.com

Query AAAA Record (IPv6)

$ dns-rust google.com AAAA
Querying 8.8.8.8:53 for AAAA record of google.com

DNS Response:
=============
ID: 6666
Response: true
Authoritative: false
Truncated: false
Recursion Desired: true
Recursion Available: true
Result Code: NoError

Questions (1):
  AAAA google.com

Answers (1):
  google.com                     299      AAAA   2607:f8b0:4004:c1b::65

Development

Prerequisites

  • Rust 1.70 or later
  • Cargo

Building

git clone https://github.com/yourusername/dns-rust.git
cd dns-rust
cargo build

Running Tests

cargo test

Running with Debug Output

cargo run -- google.com A

Project Structure

dns-rust/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs      # CLI interface and main function
β”‚   β”œβ”€β”€ lib.rs       # Library exports
β”‚   └── dns.rs       # Core DNS implementation
β”œβ”€β”€ Cargo.toml       # Project configuration
β”œβ”€β”€ README.md        # This file
└── target/          # Build artifacts (generated)

Library Usage

This project can also be used as a library in your Rust projects:

[dependencies]
dns-rust = "0.1.0"
use dns_rust::{lookup, QueryType};
use std::net::SocketAddr;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let server: SocketAddr = "8.8.8.8:53".parse()?;
    let response = lookup("google.com", QueryType::A, server)?;
    
    for answer in response.answers {
        println!("{}", answer);
    }
    
    Ok(())
}

Architecture

The DNS client is built with several key components:

  • BytePacketBuffer: Handles reading and writing DNS packets with proper bounds checking
  • DNS Structures: Type-safe representations of DNS headers, questions, and records
  • Query Engine: UDP-based DNS query implementation
  • CLI Interface: User-friendly command-line interface using clap

Security

  • No unsafe code is used anywhere in the project
  • Strict compiler warnings and lints are enforced
  • Comprehensive bounds checking for all buffer operations
  • Proper error handling throughout the codebase

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for your changes
  5. Ensure all tests pass (cargo test)
  6. Commit your changes (git commit -m 'Add some amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with Rust
  • Command-line parsing with clap

Changelog

Version 0.1.0

  • Initial release
  • Support for A, AAAA, NS, CNAME, and MX record types
  • Command-line interface
  • Comprehensive test suite
  • Library API for programmatic usage

About

A simple and fast DNS query tool written in pure Rust with no unsafe code.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages