21 个版本 (13 个破坏性更新)

0.14.0 2024年7月12日
0.13.0 2024年1月19日
0.12.0 2023年10月21日
0.11.2 2023年4月8日
0.9.0 2021年11月21日

命令行实用工具 中排名第 185

每月下载量 37

MIT/Apache

57KB
1.5K SLoC

ch4 - DNS 客户端工具

ch4 是一个围绕 rsdns 构建的 DNS 客户端 CLI 工具。

ch4 的主要目标是简洁地暴露 rsdns 的功能。它可以作为 dig 的简单替代品,并尽量与之兼容。

ch4 默认使用 tokio 异步运行时和相应的 rsdns 客户端。可以通过相同的特性集 net-tokionet-async-stdnet-smolnet-std 构建支持 rsdns 的所有客户端和异步运行时。

crates.io

特性

  1. 支持 Linux、Windows 和 MacOS
  2. 自动检测操作系统默认名称服务器

支持的 RFC

安装

cargo install ch4

ch4 目前不提供预构建的二进制文件。有关 cargo 和 Rust 工具链的安装,请参阅 rustrup.rs

示例

可以使用 @ 前缀指定名称服务器地址。

$> ch4 @8.8.8.8 A docs.rs
; <<>> ch4 0.9.0 git:a9a5dc5 <<>> @8.8.8.8 docs.rs
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32221
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;docs.rs.                      IN       A

;; ANSWER SECTION:
docs.rs.                60     IN       A      13.226.6.17
docs.rs.                60     IN       A      13.226.6.38
docs.rs.                60     IN       A      13.226.6.84
docs.rs.                60     IN       A      13.226.6.69

;; Query time: 95.678652ms
;; SERVER: 8.8.8.8:53
;; WHEN: Sat, 20 Nov 2021 23:50:24 +0200
;; MSG SIZE rcvd: 100

当未指定名称服务器时,它将从操作系统配置中自动检测。

$> ch4 crates.io ANY
; <<>> ch4 0.9.0 git:a9a5dc5 <<>> crates.io ANY
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23571
;; flags: qr rd ra; QUERY: 1, ANSWER: 12, AUTHORITY: 0, ADDITIONAL: 3

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;crates.io.                    IN         ANY

;; ANSWER SECTION:
crates.io.              300    IN         TXT    "v=spf1 include:mailgun.org ~all"
crates.io.              300    IN         MX     10 mxb.mailgun.org.
crates.io.              300    IN         MX     10 mxa.mailgun.org.
crates.io.              900    IN         SOA    ns-1064.awsdns-05.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400
crates.io.              60     IN         A      13.226.6.20
crates.io.              60     IN         A      13.226.6.118
crates.io.              60     IN         A      13.226.6.62
crates.io.              60     IN         A      13.226.6.11
crates.io.              60     IN         NS     ns-1543.awsdns-00.co.uk.
crates.io.              60     IN         NS     ns-817.awsdns-38.net.
crates.io.              60     IN         NS     ns-217.awsdns-27.com.
crates.io.              60     IN         NS     ns-1064.awsdns-05.org.

;; ADDITIONAL SECTION:
ns-217.awsdns-27.com.   20015  IN         A      205.251.192.217
ns-817.awsdns-38.net.   19938  IN         A      205.251.195.49

;; Query time: 15.686517ms
;; SERVER: 127.0.0.53:53
;; WHEN: Sat, 20 Nov 2021 23:50:36 +0200
;; MSG SIZE rcvd: 427

选项

ch4 的选项遵循 rsdns 暴露的特性。通过 --help 标志显示选项的详细列表。

$> ch4 --help
ch4 0.9.0 git:a9a5dc5
DNS Client

USAGE:
    ch4 [FLAGS] [OPTIONS] [positional]...

FLAGS:
    -h, --help
            Prints help information

        --info
            Prints build information

        --list-nameservers
            Lists system nameservers

    -V, --version
            Prints version information


OPTIONS:
    -p, --port <port>
             [default: 53]

    -l, --query-lifetime <query-lifetime>
            query lifetime (in msec). [default: 10000]

    -t, --query-timeout <query-timeout>
            query timeout (in msec). Use 0 to disable. [default: 2000]

    -r, --read <read-path>
            read responses from file

    -s, --save <save-path>
            save responses to file


ARGS:
    <positional>...
            Positional arguments ...

            Positional arguments may be specified without any particular order.
            Arguments specified later take precedence.
            Arguments that are not recognized as special are treated as names
            to be queried.


            @<nameserver> - specifies the nameserver IP address.
                            If not specified, the first nameserver from OS
                            configuration is used.

            <qtype>       - query type (A, AAAA, NS ...).
                            An argument matching any of the supported query types
                            is considered as query type. Trailing dot can be
                            used to disambiguate a query name (A.).

            +udp          - sets the Udp protocol strategy. UDP is used by default.
                            Truncated responses are retried using TCP.

            +tcp          - sets the Tcp protocol strategy.
                            Only TCP is used for all queries.

            +notcp        - sets NoTcp protocol strategy. Only UDP is used.
                            Truncated queries are returned as is, without retry.

            +[no]rec      - enables (disables) recursive query.
                            Queries are recursive by default.

            +[no]short    - enables (disables) short output.
                            When enabled, only record data is printed,
                            one record on a line.

            +bufsize=#    - sets the EDNS0 max udp payload size [512, 65535].
                            [default: 4096]

            +[no]edns[=#] - enables/disables EDNS0.
                            Optionally, sets the EDNS version [0, 255].
                            By default, EDNS is enabled with version 0.

            +[no]rust     - enables (disables) rust output.
                            When enabled, prints the response as a Rust array.

            +[no]gen      - forces generic output (RFC 3597 s. 5) on all record
                            types. By default, only unknown record types are
                            formatted this way.

通过 --list-nameservers 标志显示配置的操作系统名称服务器列表。

$> ch4 --list-nameservers
8.8.8.8
208.67.222.222
8.26.56.26

通过 --info 标志显示构建信息。

C:\> ch4.exe --info
build time:          Sat, 20 Nov 2021 23:58:49 +0000
ch4 semver:          0.9.0
git hash:            n/a
compiler:            rustc
rustc:               rustc 1.56.0 (09c42c458 2021-10-18)
cargo features:      net_tokio, tokio
cargo profile:       debug
cargo target:        x86_64-pc-windows-msvc
endianness:          little
pointer width:       64
build system name:   Windows
build os version:    Windows Server 2019 Datacenter
build cpu vendor:    GenuineIntel
build cpu brand:     Intel(R) Xeon(R) CPU E5-2673 v3 @ 2.40GHz

变更日志

变更日志维护在 CHANGELOG.md

许可证

根据您的选择,许可为以下之一

贡献

除非您明确声明,否则根据Apache-2.0许可证定义的,您有意提交包含在作品中的任何贡献,将双重许可,如上所述,没有任何额外条款或条件。

依赖项

~4–49MB
~771K SLoC