如何使用curl 解析https (DOH) 上的dns 查询?

问题描述 投票:0回答:5

我正在运行最新版本的curl (7.76.1)。

我已经设置了自己的 dnsdist 服务器/doh 代理,它查询我也设置的bind9解析器。

让curl 仅返回已解析的IP 的正确语法是什么?

当我运行以下命令时,返回的只是 example.com 的 html。我不想要 html。我想要解析的 DNS IP 地址。

curl --doh-insecure --doh-url https://10.10.10.10/dns-query http://www.example.com

如果我以详细输出运行,我可以看到以下内容。

* DOH A: 93.184.216.34
* DOH AAAA: 2606:2800:0220:0001:0248:1893:25c8:1946

如何让curl 只返回DNS dig 响应,而不返回对相关站点的HTTP GET 请求的响应?

这是完整的输出:

*   Trying 10.10.10.10:443...
* Found bundle for host 10.10.10.10: 0x55b7b243c3a0 [serially]
* Hostname 10.10.10.10 was found in DNS cache
*   Trying 10.10.10.10:443...
* Connected to 10.10.10.10 (10.10.10.10) port 443 (#2)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: none
* Connected to 10.10.10.10 (10.10.10.10) port 443 (#1)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: none
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=US; ST=Denver; O=MyCompany; OU=MyOU; CN=doh.domain.internal
*  start date: May 12 19:28:36 2021 GMT
*  expire date: May 12 19:28:36 2022 GMT
*  issuer: C=US; ST=Denver; L=Colorado; O=MyO; OU=MyOU; CN=ca.domain.internal
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> POST /dns-query HTTP/1.1
Host: 10.10.10.10
Accept: */*
Content-Type: application/dns-message
Content-Length: 33

* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=US; ST=Denver; O=MyCompany; OU=MyOU; CN=doh.domain.internal
*  start date: May 12 19:28:36 2021 GMT
*  expire date: May 12 19:28:36 2022 GMT
*  issuer: C=US; ST=Denver; L=Colorado; O=MyO; OU=MyOU; CN=ca.domain.internal
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> POST /dns-query HTTP/1.1
Host: 10.10.10.10
Accept: */*
Content-Type: application/dns-message
Content-Length: 33

* old SSL session ID is stale, removing
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Thu, 13 May 2021 18:14:40 GMT
< Connection: keep-alive
< Content-Length: 61
< Server: h2o/dnsdist
< content-type: application/dns-message
< cache-control: max-age=84701
<
* Connection #2 to host 10.10.10.10 left intact
* a DOH request is completed, 1 to go
* old SSL session ID is stale, removing
* old SSL session ID is stale, removing
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Thu, 13 May 2021 18:14:40 GMT
< Connection: keep-alive
< Content-Length: 49
< Server: h2o/dnsdist
< content-type: application/dns-message
< cache-control: max-age=69736
<
* Connection #1 to host 10.10.10.10 left intact
* a DOH request is completed, 0 to go
* DOH Host name: www.example.com
* TTL: 69736 seconds
* DOH A: 93.184.216.34
* DOH AAAA: 2606:2800:0220:0001:0248:1893:25c8:1946
*   Trying 93.184.216.34:80...
* Connected to www.example.com (93.184.216.34) port 80 (#0)
> GET / HTTP/1.1
> Host: www.example.com
> User-Agent: curl/7.76.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Age: 270738
< Cache-Control: max-age=604800
< Content-Type: text/html; charset=UTF-8
< Date: Thu, 13 May 2021 18:14:40 GMT
< Etag: "3147526947"
< Expires: Thu, 20 May 2021 18:14:40 GMT
< Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
< Server: ECS (phd/FD6D)
< Vary: Accept-Encoding
< X-Cache: HIT
< Content-Length: 1256
<
<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

    }
    div {
        width: 600px;
        margin: 5em auto;
        padding: 2em;
        background-color: #fdfdff;
        border-radius: 0.5em;
        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
    }
    a:link, a:visited {
        color: #38488f;
        text-decoration: none;
    }
    @media (max-width: 700px) {
        div {
            margin: 0 auto;
            width: auto;
        }
    }
    </style>
</head>

<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is for use in illustrative examples in documents. You may use this
    domain in literature without prior coordination or asking for permission.</p>
    <p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
* Connection #0 to host www.example.com left intact
curl https dns doh
5个回答
8
投票

根据Cloudflare

curl -vH "accept: application/dns-json" "https://cloudflare-dns.com/dns-query?name=example.com&type=AAAA"

应该会得到你想要的 DNS 结果


0
投票

curl 返回网页。

要获取IP地址,最好使用命令安装DNSLOOKUP工具

#snap install dnslookup

安装后,使用以下命令获取IP地址

#VERIFY=0 dnslookup www.example.com https://10.10.10.10/dns-query

如果你有有效的证书,VERIFY=0可以去掉。

#dnslookup www.example.com https://dns.google/dns-query

0
投票

用户可以通过

--doh-url
指定 DoH 服务器的地址,例如公共 Cloudflare 服务器:

curl --doh-url https://cloudflare-dns.com/dns-query https://github.com

0
投票

Dig 支持这一点。示例:

dig @1.1.1.1 +https public.tls-ech.dev https

https://manpages.ubuntu.com/manpages/kinetic/man1/dig.1.html


-1
投票

我知道您想使用

curl
来获得
dig
回复。但也许只是尝试使用
dig
+https
选项来代替?

dig +https @1.1.1.1 example.com
© www.soinside.com 2019 - 2024. All rights reserved.