1 个不稳定版本

0.1.0 2020年11月7日

#1 in #dog

5,388 星 & 34 关注者

130KB
3K SLoC

dog

dog 是一个命令行 DNS 客户端。

Build status Say thanks!

A screenshot of dog making a DNS request


狗狗们 可以 进行查找!

dog 是一个命令行 DNS 客户端,类似于 dig。它具有彩色输出,理解标准的命令行参数语法,支持 DNS-over-TLS 和 DNS-over-HTTPS 协议,并能输出 JSON 格式。

示例

dog example.net                          Query a domain using default settings
dog example.net MX                       ...looking up MX records instead
dog example.net MX @1.1.1.1              ...using a specific nameserver instead
dog example.net MX @1.1.1.1 -T           ...using TCP rather than UDP
dog -q example.net -t MX -n 1.1.1.1 -T   As above, but using explicit arguments

命令行选项

查询选项

<arguments>              Human-readable host names, nameservers, types, or classes
-q, --query=HOST         Host name or domain name to query
-t, --type=TYPE          Type of the DNS record being queried (A, MX, NS...)
-n, --nameserver=ADDR    Address of the nameserver to send packets to
--class=CLASS            Network class of the DNS record being queried (IN, CH, HS)

发送选项

--edns=SETTING           Whether to OPT in to EDNS (disable, hide, show)
--txid=NUMBER            Set the transaction ID to a specific value
-Z=TWEAKS                Set uncommon protocol-level tweaks

协议选项

-U, --udp                Use the DNS protocol over UDP
-T, --tcp                Use the DNS protocol over TCP
-S, --tls                Use the DNS-over-TLS protocol
-H, --https              Use the DNS-over-HTTPS protocol

输出选项

-1, --short              Short mode: display nothing but the first result
-J, --json               Display the output as JSON
--color, --colour=WHEN   When to colourise the output (always, automatic, never)
--seconds                Do not format durations, display them as seconds
--time                   Print how long the response took to arrive

安装

要安装 dog,您可以下载预编译的二进制文件,或者从源代码编译。根据您的平台,您可能可以使用操作系统包管理器安装 dog。

软件包

  • 对于 Arch Linux,安装 dog 软件包。
  • 对于 macOS 上的 Homebrew,安装 dog 公式。
  • 对于 NixOS,安装 dogdns 软件包。

下载

dog 的二进制下载文件可在 GitHub 的发布部分 获取,适用于 64 位 Windows、macOS 和 Linux 目标。它们包含编译后的可执行文件、手册页和 shell 完成脚本。

编译

dog 用 Rust 编写。您需要 rustc 版本 1.45.0 或更高版本。推荐的开发环境是使用 rustup 从 官方下载页面 安装 Rust。

要构建,下载源代码并运行

$ cargo build
$ cargo test
  • just 命令运行器可以用于运行一些有用的开发命令,类似于 make。运行 just --list 获取可用功能的概览。

  • 如果您正在为自己编译副本,请确保运行 cargo build --releasejust build-release 以利用发布模式的优化。将生成的二进制文件复制到您的 $PATH 中的文件夹中。通常 /usr/local/bin 是一个好的选择。

  • 要编译和安装手册页,您需要 pandoc。使用 just man 命令将 Markdown 编译成手册页,并将其放置在 target/man 目录中。要使用它们,将它们复制到 man 将读取的目录中。通常 /usr/local/share/man 是一个好的选择。

容器镜像

要构建 dog 的容器镜像,您可以使用 Docker 或 Kaniko。以下是一个使用 Docker 的示例

$ docker build -t dog .

您可以使用以下命令运行它

$ docker run -it --rm dog

要直接运行 dog,您可以定义以下别名

$ alias dog="docker run -it --rm dog"

端到端测试

dog 有一个以 Specsheet 检查文档编写的集成测试套件。如果您已安装副本,可以运行

$ just xtests

Specsheet 将通过网络发送 DNS 请求来测试编译的二进制文件,检查 dog 是否返回正确的结果且不会崩溃。请注意,这将暴露您的 IP 地址。有关更多信息,请阅读 xtests README

功能开关

dog 有三个 Cargo 功能可以关闭以删除功能。虽然这样做会使 dog 的功能减少,但结果是一个更小的二进制文件,构建时间更短。

有三个功能开关可用,默认都处于激活状态

  • with_idna,启用 IDNA 处理
  • with_tls,启用 DNS-over-TLS
  • with_https,启用 DNS-over-HTTPS(需要 with_tls

使用 cargo 构建使用功能开关的二进制文件。例如,要禁用 TLS 和 HTTPS 支持,但保留 IDNA 支持,可以运行

$ cargo build --no-default-features --features=with_idna

可以在运行时作为 --version 字符串的一部分检查已禁用的功能列表。


文档

有关如何使用 dog 的文档,请参阅网站:https://dns.lookup.dog/

另请参阅

mutttailsleeproff

许可

dog 的源代码根据 欧洲联盟公共许可 许可。


lib.rs:

DNS crate 是 dog 的“库”部分。它实现了 DNS 协议:从字节结构创建和解析数据包。

依赖项

~360–510KB