Skip to content

Commit

Permalink
added --list-resolvers option
Browse files Browse the repository at this point in the history
  • Loading branch information
dandyvica committed Jan 6, 2025
1 parent 13defdf commit 89022dc
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 146 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dqy"
edition = "2021"
version = "0.3.0" #:version
version = "0.5.0" #:version
authors = ["Alain Viguier <[email protected]>"]
description = """
dqy is a DNS query tool inspired by dig, drill and dog.
Expand Down Expand Up @@ -33,11 +33,11 @@ quinn = "0.11.6"
rand = "0.8.5"
rcgen = "0.13.1"
regex = "1.11.1"
reqwest = { version = "0.12.9", default-features = false, features = ["rustls-tls-webpki-roots", "blocking", "http2"] }
reqwest = { version = "0.12.12", default-features = false, features = ["rustls-tls-webpki-roots", "blocking", "http2"] }
resolving = { git = "https://github.com/dandyvica/resolving" }
rustc_version_runtime = "0.3.0"
rustls = { version = "0.23.20", default-features = false, features = ["std", "tls12", "ring"] }
rustls-pki-types = "1.1.0"
rustls-pki-types = "1.10.1"
serde = { version = "1.0.195", features = [ "derive" ] }
serde_json = { version = "1.0.111", features = ["preserve_order"] }
simplelog = "0.12.2"
Expand Down
16 changes: 16 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::dns::rfc::{flags::BitFlags, qclass::QClass, qtype::QType};
use crate::error::Error;
use crate::show::{DisplayOptions, DumpOptions};
use crate::transport::network::{IPVersion, Protocol};
use crate::transport::udp::UdpProtocol;
use crate::transport::{endpoint::EndPoint, TransportOptions};

// value of the environment variable for flags if any
Expand Down Expand Up @@ -588,6 +589,13 @@ Caveat: all options starting with a dash (-) should be placed after optional [TY
.value_parser(clap::value_parser!(PathBuf))
.help_heading("Miscellaneous options")
)
.arg(
Arg::new("list-resolvers")
.long("list-resolvers")
.long_help("Do not query but list host resolvers found and try to connect to them.")
.action(ArgAction::SetTrue)
.help_heading("Display options")
)
.arg(
Arg::new("write-response")
.long("wr")
Expand Down Expand Up @@ -952,6 +960,14 @@ Caveat: all options starting with a dash (-) should be placed after optional [TY
}
}

//───────────────────────────────────────────────────────────────────────────────────
// Dump resolvers
//───────────────────────────────────────────────────────────────────────────────────
if matches.get_flag("list-resolvers") {
UdpProtocol::list_resolvers(&options.transport)?;
std::process::exit(0);
}

Ok(options)
}
}
Expand Down
26 changes: 14 additions & 12 deletions src/transport/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ impl UdpProtocol {
})
}

// // Bind to a socket either to IPV4, IPV6 or any of these 2
// // the bind() method will chose the first one which succeeds if IPVersion::Any is passed
// fn unspec(ver: &IPVersion) -> Vec<SocketAddr> {
// match ver {
// IPVersion::Any => vec![
// SocketAddr::from((Ipv4Addr::UNSPECIFIED, 0)),
// SocketAddr::from((Ipv6Addr::UNSPECIFIED, 0)),
// ],
// IPVersion::V4 => vec![SocketAddr::from((Ipv4Addr::UNSPECIFIED, 0))],
// IPVersion::V6 => vec![SocketAddr::from((Ipv6Addr::UNSPECIFIED, 0))],
// }
// }
// display list of found host resolvers and try to bind
pub fn list_resolvers(trp_options: &TransportOptions) -> Result<()> {
// create udp socket on either V4 or V6
let unspec = trp_options.ip_version.unspecified_ip();
let sock = UdpSocket::bind(&unspec).map_err(|e| Error::Network(e, Network::Bind))?;

for addr in &trp_options.endpoint.addrs {
// try to connect
let result = if let Ok(_) = sock.connect(addr) { "OK" } else { " KO " };
println!("addr: {}, connect: {} ", addr, result);
}

Ok(())
}
}

impl Messenger for UdpProtocol {
Expand Down
6 changes: 2 additions & 4 deletions tests/test_all.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# test internet resources
venom run tests/venom/internet.yml

# test IDNA
venom run tests/venom/idna.yml

# test different ways of using an endpoint
venom run tests/venom/endpoint.yml
venom run tests/venom/endpoint-ipv4.yml
venom run tests/venom/endpoint-ipv6.yml
54 changes: 54 additions & 0 deletions tests/venom/endpoint-ipv4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# test all different endpoints (only ipv4)
name: DQY binary test (endpoints v4)
testcases:
- name: use host resolver
steps:
- script: dqy A www.google.com
assertions:
- result.code ShouldEqual 0

- name: use specific ipv4 resolver
steps:
- script: dqy A www.google.com "@1.1.1.1"
assertions:
- result.code ShouldEqual 0

- name: use specific ipv4 resolver with port number
steps:
- script: dqy A www.google.com "@1.1.1.1:53"
assertions:
- result.code ShouldEqual 0

- name: use named resolver
steps:
- script: dqy A AAAA www.google.com "@one.one.one.one"
assertions:
- result.code ShouldEqual 0

- name: use named resolver with port number
steps:
- script: dqy A AAAA www.google.com "@one.one.one.one:53"
assertions:
- result.code ShouldEqual 0

- name: use DoH resolver
steps:
- script: dqy A www.google.com "@https://cloudflare-dns.com/dns-query"
assertions:
- result.code ShouldEqual 0

- name: use DoQ resolver
steps:
- script: dqy A www.google.com "@quic://dns.adguard.com"
assertions:
- result.code ShouldEqual 0

- name: dqy axfr @nsztm1.digi.ninja zonetransfer.me
steps:
- script: dqy axfr "@nsztm1.digi.ninja" zonetransfer.me
assertions:
- result.code ShouldEqual 0




46 changes: 46 additions & 0 deletions tests/venom/endpoint-ipv6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# test all different endpoints
name: DQY binary test (endpoints v6)
testcases:
- name: use specific ipv6 resolver
steps:
- script: dqy A www.google.com "@2606:4700:4700::1111" -6
assertions:

- name: use specific ipv6 resolver with port number
steps:
- script: dqy A www.google.com "@[2606:4700:4700::1111]:53" -6
assertions:
- result.code ShouldEqual 0

- name: use named resolver ipv6
steps:
- script: dqy A AAAA www.google.com "@one.one.one.one" -6
assertions:
- result.code ShouldEqual 0

- name: use named resolver ipv6 TCP
steps:
- script: dqy A AAAA www.google.com "@one.one.one.one" -6 --tcp
assertions:
- result.code ShouldEqual 0

- name: use named resolver with port number ipv6
steps:
- script: dqy A AAAA www.google.com "@one.one.one.one:53" -6
assertions:
- result.code ShouldEqual 0

- name: use DoH resolver
steps:
- script: dqy A www.google.com "@https://cloudflare-dns.com/dns-query" -6
assertions:
- result.code ShouldEqual 0

- name: use DoQ resolver
steps:
- script: dqy A www.google.com "@quic://dns.adguard.com" -6
assertions:
- result.code ShouldEqual 0



73 changes: 0 additions & 73 deletions tests/venom/endpoint.yml

This file was deleted.

54 changes: 0 additions & 54 deletions tests/venom/internet.yml

This file was deleted.

0 comments on commit 89022dc

Please sign in to comment.