首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何使用curl解析dns over https (DOH)查询?

如何使用curl解析dns over https (DOH)查询?
EN

Stack Overflow用户
提问于 2021-05-14 02:23:11
回答 1查看 718关注 0票数 0

我运行的是最新版本的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

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

代码语言:javascript
代码运行次数:0
运行
复制
* DOH A: 93.184.216.34
* DOH AAAA: 2606:2800:0220:0001:0248:1893:25c8:1946

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

下面是完整的输出:

代码语言:javascript
代码运行次数:0
运行
复制
*   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
EN

回答 1

Stack Overflow用户

发布于 2021-07-06 14:37:50

curl返回一个网页。

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

代码语言:javascript
代码运行次数:0
运行
复制
#snap install dnslookup

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

代码语言:javascript
代码运行次数:0
运行
复制
#VERIFY=0 dnslookup www.example.com https://10.10.10.10/dns-query

如果您拥有有效的证书,则可以删除VERIFY=0。

代码语言:javascript
代码运行次数:0
运行
复制
#dnslookup www.example.com https://dns.google/dns-query
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67524278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档