Toc的使用和配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_1290259791/article/details/82056703

1、Tor是什么?

Tor(The Onion Router,洋葱路由器)是实现匿名通信的自由软件。Tor是第二代洋葱路由的一种实现,用户通过Tor可以在因特网上进行匿名交流。
而对于爬虫爱好者来说,Tor会隐藏你的真实ip地址,导致被爬网站的网管无法封掉你的ip(当然是在对方觉得精确定位你的ip无价值的情况下)安全是相对的,匿名也是相对的。

2、安装Tor

tor分为浏览器版本和命令行版本。前者针对普通用户来使用,使用的是【改造办的火狐浏览器】,下载后就可以使用。
而命令行版的就是在电脑或者服务器的开一个服务,监听默认的9050端口。
1.图形界面版下载地址
2.命令行版brew install tor

3、配置Tor

在下面路径/usr/local/etc/tor找到文件torrc.sample,拷贝一份命名为torrc

常用配置的参数

参数 作用
Socks5Proxy 前置 Socks 代理端口
HTTPProxy 前置 HTTP 代理端口
HTTPSProxy 前置 HTTPS 代理端口
SocksProt 外部程序访问 Tor 的端口
MaxCircuitDirtiness 自动切换 ip 的时间间隔

我的配置

CookieAuthentication 1

# shadowsocks 客户端提供的 HTTP 代理地址为 127.0.0.1:1087
#HTTPProxy 127.0.0.1:1087
#HTTPSProxy 127.0.0.1:1087
Socks5Proxy 127.0.0.1:1086
# 外部程序Tor 的端口
SocksPort 9050
MaxCircuitDirtiness 10 seconds

直接在命令面板执行tor命令输出。注意:不配置shadowsocks的代理地址不会连接成功。

➜  tor tor
Aug 25 23:41:30.380 [notice] Tor 0.3.3.9 (git-45028085ea188baf) running on Darwin with Libevent 2.1.8-stable, OpenSSL 1.0.2o, Zlib 1.2.11, Liblzma N/A, and Libzstd N/A.
Aug 25 23:41:30.382 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Aug 25 23:41:30.382 [notice] Read configuration file "/usr/local/etc/tor/torrc".
Aug 25 23:41:30.390 [notice] Scheduler type KISTLite has been enabled.
Aug 25 23:41:30.390 [notice] Opening Socks listener on 127.0.0.1:9050
Aug 25 23:41:30.000 [notice] Parsing GEOIP IPv4 file /usr/local/Cellar/tor/0.3.3.9/share/tor/geoip.
Aug 25 23:41:30.000 [notice] Parsing GEOIP IPv6 file /usr/local/Cellar/tor/0.3.3.9/share/tor/geoip6.
Aug 25 23:41:30.000 [notice] Bootstrapped 0%: Starting
Aug 25 23:41:31.000 [notice] Starting with guard context "default"
Aug 25 23:41:31.000 [notice] Bootstrapped 80%: Connecting to the Tor network
Aug 25 23:41:32.000 [notice] Bootstrapped 85%: Finishing handshake with first hop
Aug 25 23:41:35.000 [notice] Bootstrapped 90%: Establishing a Tor circuit
Aug 25 23:41:37.000 [notice] Tor has successfully opened a circuit. Looks like client functionality is working.
Aug 25 23:41:37.000 [notice] Bootstrapped 100%: Done

4、Chrome中SwitchySharp的配置


访问网址https://check.torproject.org/查看是否配置Tor成功。

5、Python来测试ip

我的配置是10s切换依次IP。
首先下载模块pip install PySocks

import socks
import requests
import socket


socks.set_default_proxy(proxy_type=socks.SOCKS5, addr="127.0.0.1", port=9050)
socket.socket = socks.socksocket
resp = requests.get('http://api.ipify.org/').text
print(resp)

猜你喜欢

转载自blog.csdn.net/qq_1290259791/article/details/82056703
toc
今日推荐