cURL 指定出站 IP - Windows

cURL 指定出站 IP - Windows

我已将我的 Windows AWS 实例配置为使用两个 IP 地址,并且希望能够选择使用这两个 IP 中的哪一个进行使用 curl(pycurl)的 HTTP GET 请求。

我希望在服务器端看起来有两个独立的客户端 - 几乎就像一台机器使用自己作为代理一样。

我已将我的实例配置为使用 1.1.1.1 作为静态 IP,并使用 2.2.2.2 作为附加(代理)IP 地址。

> curl --interface 1.1.1.1 example.com

成功,但是,尝试使用其他 IP 地址会导致超时。

> curl --interface 2.2.2.2 example.com
curl: (7) Failed to connect to example.com port 80: Timed out

设置详细标志

> curl --interface 2.2.2.2 --verbose example.com
*   Trying 93.184.216.34:80...
* TCP_NODELAY set
* Name '2.2.2.2' family 2 resolved to '2.2.2.2' family 2
* Local port: 0
* connect to 93.184.216.34 port 80 failed: Timed out
* Failed to connect to example.com port 80: Timed out
* Closing connection 0
curl: (7) Failed to connect to example.com port 80: Timed out

有人能解释一下为什么使用第二个 IP 时这个连接可能会失败吗(以及如何在 Windows 中解决这个问题)?

先感谢您!

答案1

听起来这可能是路由问题,您能将pingtraceroute发送到该地址吗?在 PowerShell 中检查route printGet-NetRoute以了解是否设置了正确的网关 - 每个网关的第三列将告诉您请求对于给定地址的去向(您可能想要查找相应NextHopDestinationPrefix 0.0.0.0/0)。

您需要查找设备如何将您的请求路由到不同接口的不同 IP 的问题,以解决问题。

相关内容