选择出局ip为curl请求 [英] select outgoing ip for curl request
本文介绍了选择出局ip为curl请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有两个不同IP的服务器。我需要发送奇怪的卷曲请求从第一个IP,甚至从第二个。如何选择传出的IP地址?
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?
我的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地址或主机名。
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.
这篇关于选择出局ip为curl请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文