使用 dig 和 curl 确定网站的物理主机
Posted
技术标签:
【中文标题】使用 dig 和 curl 确定网站的物理主机【英文标题】:Determining the physical host of a website using dig and curl 【发布时间】:2021-11-08 18:58:46 【问题描述】:这是基于 Olivier Bonaventure 在“计算机网络:原理、协议和实践”一书中提出的问题。我在我的 Linux 终端上阅读了 dig 和 curl 的手册页,但我似乎无法理解它如何帮助找出给定网站的物理主机。我们是否分别使用这两个语句?还是我们将它们放入一个语句中?
【问题讨论】:
【参考方案1】:我很确定这里的意思是找出正在使用的 IP。
您将使用 dig 来获取 A 记录:
~ → dig www.info.ucl.ac.be
; <<>> DiG 9.10.6 <<>> www.info.ucl.ac.be
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58340
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.info.ucl.ac.be. IN A
;; ANSWER SECTION:
www.info.ucl.ac.be. 7200 IN A 130.104.228.160
;; Query time: 459 msec
;; SERVER: 2001:558:feed::1#53(2001:558:feed::1)
;; WHEN: Wed Oct 06 12:27:23 PDT 2021
;; MSG SIZE rcvd: 63
这将为您提供以下物理主机:130.104.228.160
你可以用 curl 做同样的事情:
~ → curl -svo /dev/null https://www.info.ucl.ac.be
* Trying 130.104.228.160...
* TCP_NODELAY set
* Connected to www.info.ucl.ac.be (130.104.228.160) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
[232 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
[108 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
[6286 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
[300 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
[4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
[37 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
[1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
[16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
[1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
[16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: C=BE; postalCode=1348; ST=Brabant wallon; L=Louvain-la-Neuve; street=Place de l'Universit�, 1; O=Universit� catholique de Louvain; OU=INGI; CN=www.info.ucl.ac.be
* start date: Jul 13 00:00:00 2020 GMT
* expire date: Jul 13 23:59:59 2022 GMT
* subjectAltName: host "www.info.ucl.ac.be" matched cert's "www.info.ucl.ac.be"
* issuer: C=NL; O=GEANT Vereniging; CN=GEANT OV RSA CA 4
* SSL certificate verify ok.
> GET / HTTP/1.1
> Host: www.info.ucl.ac.be
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Wed, 06 Oct 2021 19:27:40 GMT
< Server: Apache/2.4.37 (centos) OpenSSL/1.1.1g
< X-Powered-By: php/7.2.24
< Location: http://www.uclouvain.be/ingi.html
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
<
* Connection #0 to host www.info.ucl.ac.be left intact
* Closing connection 0
特别注意输出:
已连接到 www。信息。伦敦大学交流。是 (130.104.228.160) 端口 443 (#0)
【讨论】:
以上是关于使用 dig 和 curl 确定网站的物理主机的主要内容,如果未能解决你的问题,请参考以下文章