我试图--resolve在执行 HTTP 请求时使用 curl 的选项连接到指定的 IP 地址,但 curl 不断恢复到我的本地 DNS 缓存/解析器检索到的 IP 地址。
命令:
curl -s -S -I -H "Host: example.com" --resolve example.com:80:1.1.1.1 --verbose http://example.com/
Run Code Online (Sandbox Code Playgroud)
(whereexample.com替换为我的域名,1.1.1.1替换为想要的目的IP地址)
结果:
* Added example.com:80:1.1.1.1 to DNS cache
* Hostname was NOT found in DNS cache
* Trying 2.2.2.2...
* Connected to example.com (2.2.2.2) port 80 (#0)
> HEAD / HTTP/1.1
> User-Agent: curl/7.35.0
> Accept: */*
> Host: example.com
Run Code Online (Sandbox Code Playgroud)
(where2.2.2.2被缓存在我的本地 DNS 解析器中的 IP 地址替换为我的域名)
因此,看起来 curl 尝试添加1.1.1.1到 DNS 缓存中example.com,但不知何故失败并恢复到原始 IP 地址。
关于如何解决此问题或进一步排除故障以找出其不起作用的任何想法?
在尝试使用其他域名后,我发现问题是由--resolve选项和 URL 中的域名不匹配引起的(一个有www,另一个没有)。用户错误!
不正确:
curl -s -S -I -H "Host: example.com" --resolve example.com:80:1.1.1.1 --verbose http://www.example.com/
Run Code Online (Sandbox Code Playgroud)
正确的:
curl -s -S -I -H "Host: example.com" --resolve example.com:80:1.1.1.1 --verbose http://example.com/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40967 次 |
| 最近记录: |