curl怎样获取指定IP主机的信息

使用CDN后,网站域名对应的是N台CDN主题,例如新浪网,通过 NSLOOKUP 就可以看出,它指向了多个IP。

Z:\>nslookup www.sina.com.cn文章源自堕落的鱼-https://www.duoluodeyu.com/2482.html

Server: c.center-dns.jsinfo.net文章源自堕落的鱼-https://www.duoluodeyu.com/2482.html

Address: 61.177.7.1文章源自堕落的鱼-https://www.duoluodeyu.com/2482.html

Name: newsnj.sina.com.cn文章源自堕落的鱼-https://www.duoluodeyu.com/2482.html

Addresses: 202.102.75.169, 202.102.75.170, 202.102.75.161, 202.102.75.162 202.102.75.163, 202.102.75.164, 202.102.75.165, 202.102.75.166, 202.10 2.75.167 202.102.75.168文章源自堕落的鱼-https://www.duoluodeyu.com/2482.html

Aliases: www.sina.com.cn, jupiter.sina.com.cn文章源自堕落的鱼-https://www.duoluodeyu.com/2482.html

使用 curl -I http://www.sina.com.cn/ 可以得到 HTTP 头信息,文章源自堕落的鱼-https://www.duoluodeyu.com/2482.html

但是curl获取的主机是从DNS服务器随机取到的,文章源自堕落的鱼-https://www.duoluodeyu.com/2482.html

怎么样才能查看指定IP上的HTTP信息呢?文章源自堕落的鱼-https://www.duoluodeyu.com/2482.html

使用IP访问,并使用 -H 参数添加 HTTP 头“Host:www.sina.com.cn”,就可以了!文章源自堕落的鱼-https://www.duoluodeyu.com/2482.html

D:\>curl -I http://www.sina.com.cn/

HTTP/1.1 200 OK

Via: 1.0 nanjing75-162.HP08040106.sina.com.cn:80 (squid/2.6.STABLE13), 1.0 TRFW

Connection: Keep-Alive

Proxy-Connection: Keep-Alive

Content-Length: 390160

Expires: Fri, 26 Sep 2008 05:22:11 GMT

Date: Fri, 26 Sep 2008 05:21:11 GMT

Content-Type: text/html

ETag: "5c2d7-457c5a8340d40"

Server: Apache

Last-Modified: Fri, 26 Sep 2008 05:19:09 GMT

Accept-Ranges: bytes

X-Powered-By: mod_xlayout_jh/0.0.1vhs.markIII.remix

Cache-Control: max-age=60

Vary: Accept-Encoding

X-Cache: HIT from nanjing75-162.HP08040106.sina.com.cn

从 DNS 解析到 202.102.75.162 主机

D:\>curl -I -H "Host:www.sina.com.cn" http://202.102.75.169/

HTTP/1.1 200 OK

Via: 1.0 nanjing75-169.HP08040113.sina.com.cn:80 (squid/2.6.STABLE13), 1.0 TRFW

Connection: Keep-Alive

Proxy-Connection: Keep-Alive

Content-Length: 390160

Age: 3

Expires: Fri, 26 Sep 2008 05:21:07 GMT

Date: Fri, 26 Sep 2008 05:20:07 GMT

Content-Type: text/html

ETag: "5c2d7-457c5a8340d40"

Server: Apache

Last-Modified: Fri, 26 Sep 2008 05:19:09 GMT

Accept-Ranges: bytes

X-Powered-By: mod_xlayout_jh/0.0.1vhs.markIII.remix

Cache-Control: max-age=60

Vary: Accept-Encoding

X-Cache: HIT from nanjing75-169.HP08040113.sina.com.cn

CURL通过设定 -H 参数添加 HTTP 头“Host:www.sina.com.cn”,就可以了实现获取指定IP主机的信息。

 
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证