为 curl 请求选择传出 ip [英] select outgoing ip for curl request
问题描述
我的服务器有两个不同的 IP.我需要从第一个 IP 甚至第二个 IP 发送奇怪的 curl 请求.如何选择外发 IP 地址?
我的 PHP 脚本是这样的:
$curlh = curl_init($url);curl_setopt($curlh, CURLOPT_USERAGENT, $uagent);curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);$result = curl_exec($curlh);
我该怎么做?
您可能想尝试设置 CURLOPT_INTERFACE
选项:
curl_setopt($curlh, CURLOPT_INTERFACE, "xxx.xxx.xxx.xxx");
<块引用>
CURLOPT_INTERFACE: 要使用的传出网络接口的名称.这可以是接口名称、IP 地址或主机名.
<小时>修复示例,如@Michael Hart 指出 在另一个答案中指出.
I have a server with two different IPs. I need to send odd curl requests from first IP, and even from the second one. How can I select outgoing IP address?
My PHP script is something like this:
$curlh = curl_init($url);
curl_setopt($curlh, CURLOPT_USERAGENT, $uagent);
curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curlh);
How can I do so?
You may want to try setting the CURLOPT_INTERFACE
option:
curl_setopt($curlh, CURLOPT_INTERFACE, "xxx.xxx.xxx.xxx");
CURLOPT_INTERFACE: The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.
From: php Manual: curl_setopt
EDIT: Fixing example, as @Michael Hart pointed out pointed out in the other answer.
这篇关于为 curl 请求选择传出 ip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!