简体   繁体   English

使用 curl --resolve 和 http 代理

[英]Use curl --resolve with http proxy

There is a --resolve option in the curl utility that allows you to add a DNS entry and force a certain IP address when calling a host. curl实用程序中有一个--resolve选项,允许您添加 DNS 条目并在调用主机时强制使用某个 IP 地址。

Since version 7.21.3 cURL allows specifying an IP address, thus forging the hostname for the request.由于版本 7.21.3 cURL 允许指定 IP 地址,从而为请求伪造主机名。

$ curl --resolve www.example.com:80:127.0.0.1 http://www.example.com/ $ curl --resolve www.example.com:80:127.0.0.1 http://www.example.com/

The --resolve switch allows you to tell curl which address to request when it would resolve a given hostname. --resolve 开关允许您告诉 curl 在解析给定主机名时请求哪个地址。 In the above snippet cURL uses 127.0.0.1 (localhost) instead of resolving www.example.com via DNS.在上面的片段中,cURL 使用 127.0.0.1 (localhost) 而不是通过 DNS 解析 www.example.com。

This option works correctly when used without an http proxy, the DNS entry is found in cache.此选项在没有 http 代理的情况下使用时正常工作,DNS 条目可在缓存中找到。

The problem is I would like to use this option simultaneously with the curl --proxy parameter.问题是我想将此选项与 curl --proxy参数同时使用。 When this last parameter is set, the DNS entry is not found when calling the same host.当设置最后一个参数时,调用同一主机时找不到 DNS 条目。

$ curl --proxy 1.2.3.4:80 --resolve www.example.com:80:127.0.0.1 http://www.example.com/

Any idea how to get around this problem?知道如何解决这个问题吗?

I have an idea that the proxy is using its own DNS cache and we can't change it but maybe I'm wrong ?我有一个想法,代理正在使用自己的 DNS 缓存,我们无法更改它,但也许我错了?

如果您有权访问它,您还可以修改代理服务器中的 /etc/hosts。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM