代理IP的使用

curl

curl http://www.icanhazip.com/
curl -x 127.0.0.1:3128 http://www.icanhazip.com/

socks5

curl --socks5 127.0.0.1:3129 http://www.icanhazip.com/

php

define(URL, 'http://www.icanhazip.com/');
define(PROXY, '127.0.0.1');
define(PORT, 3128);

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, URL);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_PROXY, PROXY);
curl_setopt($curl, CURLOPT_PROXYPORT, PORT);
//curl_setopt($curl, CURLOPT_PROXYUSERPWD, "代理用户名:代理密码");

curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$tmpInfo = curl_exec($curl);
curl_close($curl);
echo $tmpInfo;

感谢阅读这篇文章,如果你喜欢,或者遇到了问题,可以关注我的公众号