刚刚弄好了CentOS 5.4 + Tor + Privoxy + PHP的测试,赶快记一下,哈哈,成功啦!~~
本文为 21andy.com 原创,转载请注明出处,否则后果自负
http://www.21andy.com/blog/20100416/1882.html
需要已经安装好 libevent
# vim /etc/yum.repos.d/dag.repo
放入如下内容
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
# vim /etc/yum.repos.d/torproject.repo
输入如下内容
[torproject]
name=Tor and Vidalia
enabled=1
autorefresh=0
baseurl=http://deb.torproject.org/torproject.org/rpm/centos5/
type=rpm-md
gpgcheck=1
gpgkey=http://deb.torproject.org/torproject.org/rpm/RPM-GPG-KEY-torproject.org
name=Tor and Vidalia
enabled=1
autorefresh=0
baseurl=http://deb.torproject.org/torproject.org/rpm/centos5/
type=rpm-md
gpgcheck=1
gpgkey=http://deb.torproject.org/torproject.org/rpm/RPM-GPG-KEY-torproject.org
安装 Tor + Privoxy
# yum install tor privoxy
不出意外就安装成功了
接下来配置 Privoxy
# vim /etc/privoxy/config
增加一行,注意后面有个.哦
forward-socks4a / 127.0.0.1:9050 .
删除或注释掉以下2行,这样就不留马脚啦!
#logfile logfile
#jarfile jarfile
#jarfile jarfile
OK,启动服务
# service tor start
# service privoxy start
# service privoxy start
Tor 的配置文件在
# vim /etc/tor/torrc
# vim /etc/tor/tor-tsocks.conf
# vim /etc/tor/tor-tsocks.conf
可以在这里改端口啥的
要启用 PHP 来切换 tor 代理,得这么做
# vim /etc/tor/torrc
加入以下3行
DataDirectory /var/lib/tor
ControlPort 9051
CookieAuthentication 1
ControlPort 9051
CookieAuthentication 1
如何切换,在刚才的 php + tor 里我发过代码
建一个 php 文件测试一下
<?php
function tor_wrapper($url) {
$ua = array('Mozilla','Opera','Microsoft Internet Explorer','ia_archiver');
$op = array('Windows','Windows XP','Linux','Windows NT','Windows 2000','OSX');
$agent = $ua[rand(0,3)].'/'.rand(1,8).'.'.rand(0,9).' ('.$op[rand(0,5)].' '.rand(1,7).'.'.rand(0,9).'; en-US;)';
# Tor address & port
$tor = '127.0.0.1:9050';
# set a timeout.
$timeout = '300';
$ack = curl_init();
curl_setopt ($ack, CURLOPT_PROXY, $tor);
curl_setopt ($ack, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
curl_setopt ($ack, CURLOPT_URL, $url);
curl_setopt ($ack, CURLOPT_HEADER, 0);
curl_setopt ($ack, CURLOPT_USERAGENT, $agent);
curl_setopt ($ack, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ack, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ack, CURLOPT_TIMEOUT, $timeout);
$syn = curl_exec($ack);
# $info = curl_getinfo($ack);
curl_close($ack);
# $info['http_code'];
return $syn;
}
# example:
$wrapped = tor_wrapper("http://www.21andy.com/ip/api.php");
echo $wrapped;
function tor_wrapper($url) {
$ua = array('Mozilla','Opera','Microsoft Internet Explorer','ia_archiver');
$op = array('Windows','Windows XP','Linux','Windows NT','Windows 2000','OSX');
$agent = $ua[rand(0,3)].'/'.rand(1,8).'.'.rand(0,9).' ('.$op[rand(0,5)].' '.rand(1,7).'.'.rand(0,9).'; en-US;)';
# Tor address & port
$tor = '127.0.0.1:9050';
# set a timeout.
$timeout = '300';
$ack = curl_init();
curl_setopt ($ack, CURLOPT_PROXY, $tor);
curl_setopt ($ack, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
curl_setopt ($ack, CURLOPT_URL, $url);
curl_setopt ($ack, CURLOPT_HEADER, 0);
curl_setopt ($ack, CURLOPT_USERAGENT, $agent);
curl_setopt ($ack, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ack, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ack, CURLOPT_TIMEOUT, $timeout);
$syn = curl_exec($ack);
# $info = curl_getinfo($ack);
curl_close($ack);
# $info['http_code'];
return $syn;
}
# example:
$wrapped = tor_wrapper("http://www.21andy.com/ip/api.php");
echo $wrapped;
刚才的 PHP + Tor 文章里 http://www.21andy.com/blog/20100416/1879.html
curl默认用的是http代理,所以这里我加上了
curl_setopt ($ack, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
这样就可以直接使用tor的 socks4 代理了
本文为 21andy.com 原创,转载请注明出处,否则后果自负
http://www.21andy.com/blog/20100416/1882.html
试运行一下,查查IP地址,看到输出结果了,哈哈,不过连接速度有点点慢,还是很爽的,现在好多代理用啦
# php test.php
62.212.67.209 来自 荷兰
没有评论:
发表评论