首页 文章

如何获取IP地址何时浏览域名?

提问于
浏览
0
dig www.sina.com.cn
jupiter.sina.com.cn.        30      IN      A       183.232.24.117
jupiter.sina.com.cn.        30      IN      A       183.232.24.115
jupiter.sina.com.cn.        30      IN      A       183.232.24.112
jupiter.sina.com.cn.        30      IN      A       183.232.24.114
jupiter.sina.com.cn.        30      IN      A       183.232.24.111
jupiter.sina.com.cn.        30      IN      A       183.232.24.113
jupiter.sina.com.cn.        30      IN      A       183.232.24.116

这意味着域名www.sina.com.cn可以被解析为如上所述的七个ips之一 .

我想知道以下代码究竟要访问哪个ip .

import requests
source = 'http://www.sina.com.cn'
r = requests.get(source)
print(r.headers)

{'Server':'nginx','Expires':'周五,2017年2月3日06:41:23 GMT','日期':'周五,2017年2月3日06:40:23 GMT','年龄':' 10','Content-Encoding':'gzip','Content-Length':'133766','Content-Type':'text / html','X-Cache':'来自cmnet.xxg.18a4的HIT . 34.spool.sina.com.cn','X-Powered-By':'shci_v1.03','Vary':'Accept-Encoding','Cache-Control':'max-age = 60',' Last-Modified':'星期五,03二月2017 06:40:00 GMT'}

没有IP地址信息 .

ping  cmnet.xxg.18a4.34.spool.sina.com.cn
ping: unknown host cmnet.xxg.18a4.34.spool.sina.com.cn

使用上面的python代码向域名 www.sina.com.cn 发送请求时访问了哪个IP地址?打开wireshark来监控进程 .

enter image description here

此时www.sina.com.cn被解析为183.232.24.111,也许下次它可能被解析为183.232.24.117,无论哪一个,我希望它由我的python代码显示 .

enter image description here

ip将在范围内从一个更改为另一个(183.232.24.111-183.232.24.117) .

1 回答

  • 1
    >>> import requests
    >>> r = requests.get('http://www.sina.com.cn', stream=True)
    >>> r.raw._connection.sock.getpeername()
    ('151.249.91.56', 80)
    

    Body Content Workflow

    more

相关问题