Skip to content

Commit

Permalink
wrote a better README
Browse files Browse the repository at this point in the history
  • Loading branch information
dandyvica committed Jan 28, 2024
1 parent d535ae9 commit c688a91
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 25 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ license = "MIT"
autotests = false
edition = "2021"
rust-version = "1.75"
doctest = false

[workspace.dependencies]
bytes = "1.5.0"
Expand Down
62 changes: 58 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[![Actions](https://github.com/dandyvica/dqy/actions/workflows/rust.yml/badge.svg)](https://github.com/dandyvica/dqy/actions/workflows/rust.yml)

Note: this is currently under development in my free time. Version is not even yet 0.1.0
but hope to release executables in a couple of weeks.
Note: this is currently under development in my free time. Version is not even yet 0.1.0

# dqy
A DNS query tool inspired by _dig_, _drill_ and _dog_.
Expand All @@ -12,9 +11,10 @@ This tool is written in pure Rust with the following features:
* depends only on _rustls_ (no _openssl_)
* support upd, tcp, DoT and DoH protocols (DoQ to come)
* available on: Linux (x64, ARM64, musl), Window, MacOs
* IDNA support
* possible outputs:
* plain vanilla ascii
* Json
* Json (useful with ```jq```)
* ability to call a Lua script to fine tune the output

## Supported resource records
Expand Down Expand Up @@ -76,6 +76,31 @@ The _--json_ and _--json-pretty_ options allows to display output data in JSON f
## Lua scripting support
Using _-l <Lua source file>_, all DNS data are sent as global variables to the Lua interpreter which makes it possible to format the output in a very flexible manner.

As Lua tables can't keep the order of fields when created, a special Lua module is provided in the repository: ```rdata.lua``` which contains RRs list of fields in an ordered way, and a helper function to display ```RData```.

To use that module, you need to set the ```LUA_PATH``` module:

* ```export LUA_PATH=/home/johndoe/lua/rdata.lua``` on UNIX platforms
* ```Set-Item -Path env:LUA_PATH -Value "C:\Users\Moi\projects\dqy\lua\rdata.lua"``` on Windows PowerShell

Two Lua examples are also provided:

* ```dig.lua``` which mimics ```dig``` output
* ```dog.lua``` which mimics ```dog``` output (to some extent without colors)

Lua uses 2 global variables which are created by ```dqy```:

* ```dns``` which contains the list of queries and responses for each type requested
* ```info``` for some meta information like elpased time, bytes count sent and received etc

If you want to dump the whole Lua table, just use this Lua code posted here:
https://stackoverflow.com/questions/9168058/how-to-dump-a-table-to-console


## Bugs
Beware it's a humble utility and probably buggy. Feel free to test it and report issues.
Specially in the display options, not all are implemented or even specially useful because of the Lua scripting or JSON output.

## Roadmap
Following is a tentative roadmap:

Expand All @@ -92,7 +117,36 @@ Just type:
$ dqy --help
```

## Examples
If no resolver is given, OS configured resolvers are fetched from:
* ```resolv.conf``` file form UNIX platforms
* using the ```GetAdaptersAddresses``` Windows API for Windows platforms
using the resolver crate: https://github.com/dandyvica/resolver

## Compiling

Compiled and tests with Rust 1.75.

* on Linux: make sure pkg-config is installed ```sudo apt-get install pkg-config``` and Lua dev libs too: ```sudo apt install liblua5.4-dev```
* OS/X: ```brew install pkg-config``` and ```brew install lua@5.4```
* on Windows (using ```PowerShell```)
* download ```pkg-config```: https://download.gnome.org/binaries/win32/dependencies/
* download ```Lua5.4 libs```: https://luabinaries.sourceforge.net/
* set environment variables:
* ```Set-Item -Path env:LUA_LIB_NAME -Value "lua54"```
* ```Set-Item -Path env:LUA_LIB -Value "mypath_where_lua54_lib_are"```
* then: ```cargo build --release```

## Exit codes
* 0: no error
* 1: I/O error (probably a networking error)
* 2: UTF-8 conversion error
* 3: IP address parsing error from a string
* 4: internal DNS protocol error
* 5: DoH error
* 6: DoT error
* 7: error fetching OS resolvers
* 8: network timeout error
* 9: Lua script error



Expand Down
3 changes: 2 additions & 1 deletion args/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ version.workspace = true
authors.workspace = true
description.workspace = true
documentation.workspace = true
edition = "2021"
edition.workspace = true
doctest.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
37 changes: 22 additions & 15 deletions args/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,21 @@ impl CliOptions {
.version("0.1")
.author("Alain Viguier dandyvica@gmail.com")
.about(
r#"A simple DNS query client
Project home page: https://github.com/dandyvica/dqy
r#"A DNS query tool inspired by _dig_, _drill_ and _dog_.
Project home page: https://github.com/dandyvica/dqy
"#,
)
.after_long_help("Examples:")
.after_long_help(r#"Examples:
- dqy AAAA www.google.com
- dqy A AAAA MX TXT www.example.com @1.1.1.1 --no-opt
"#)
.bin_name("dqy")
.no_binary_name(true)
.override_usage("dqy [TYPES] [DOMAIN] [RESOLVER] [OPTIONS]")
.arg(
Arg::new("type")
.short('t')
Expand Down Expand Up @@ -150,14 +157,14 @@ impl CliOptions {
.action(ArgAction::Set)
.value_name("PTR")
)
.arg(
Arg::new("server")
.short('s')
.long("server")
.long_help("Server name to query.")
.action(ArgAction::Set)
.value_name("SERVER")
)
// .arg(
// Arg::new("server")
// .short('s')
// .long("server")
// .long_help("Server name to query.")
// .action(ArgAction::Set)
// .value_name("SERVER")
// )
.arg(
Arg::new("trace")
.long("trace")
Expand Down Expand Up @@ -250,7 +257,7 @@ impl CliOptions {
.action(ArgAction::Set)
.num_args(1..=6)
.value_name("FLAGS")
.value_parser(["aa", "ad", "cd", "ra", "rd", "tc"])
.value_parser(["aa", "ad", "cd", "ra", "rd", "tc", "z"])
.help_heading("Transport options")
)
.arg(
Expand All @@ -260,7 +267,7 @@ impl CliOptions {
.action(ArgAction::Set)
.num_args(1..=6)
.value_name("FLAGS")
.value_parser(["aa", "ad", "cd", "ra", "rd", "tc"])
.value_parser(["aa", "ad", "cd", "ra", "rd", "tc", "z"])
.help_heading("Transport options")
)
//───────────────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -417,7 +424,7 @@ impl CliOptions {
Arg::new("verbose")
.short('v')
.long("verbose")
.long_help("Verbose mode.")
.long_help("Verbose mode, from info -v to trace -vvvvv.")
.action(ArgAction::Count)
.help_heading("Display options")
)
Expand Down
3 changes: 2 additions & 1 deletion dns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ version.workspace = true
authors.workspace = true
description.workspace = true
documentation.workspace = true
edition = "2021"
edition.workspace = true
doctest.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions dqy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors.workspace = true
description.workspace = true
documentation.workspace = true
edition.workspace = true
doctest.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
10 changes: 9 additions & 1 deletion dqy/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! A DNS resource query tool
use std::{net::SocketAddr, process::ExitCode, time::Instant};
use std::{fmt, net::SocketAddr, process::ExitCode, time::Instant};

use log::debug;
use serde::Serialize;
Expand Down Expand Up @@ -35,6 +35,14 @@ struct Info {
bytes_received: usize,
}

impl fmt::Display for Info {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "\nendpoint: {} ({})\n", self.endpoint, self.mode)?;
write!(f, "elapsed: {} ms\n", self.elapsed)?;
write!(f, "sent:{}, received:{} bytes", self.bytes_sent, self.bytes_received)
}
}

// use this trick to be able to display error
fn main() -> ExitCode {
let res = run();
Expand Down
7 changes: 4 additions & 3 deletions dqy/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,13 @@ impl DnsProtocol {
});
println!("{}", serde_json::to_string(&j).unwrap());
} else {
// if display_options.question {
// println!("{:?}", msg_list.query);
// }
for msg in messages.iter() {
msg.response().show(display_options);
}

if display_options.stats {
println!("{}", info);
}
}
}
}
1 change: 1 addition & 0 deletions error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors.workspace = true
description.workspace = true
documentation.workspace = true
edition.workspace = true
doctest.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down

0 comments on commit c688a91

Please sign in to comment.