问题描述
我真的需要一些帮助自动化Tor在网站上做某事(在这种情况下,检查一些投票),然后重新启动Tor与一个新的身份。我从来没有做过任何遥远的接近这一点。我只知道HTML,CSS和JS相当不错。
I really need some help with automating Tor to do something on a site (in this case, check something on a poll) and then restart Tor with a new identity. I have never done anything remotely close to this. I only know HTML, CSS and JS fairly well.
现在,总结一下,我想创建一个循环,重复访问Tor上的网站,检查网站,然后重新启动Tor与一个新的身份。
Now, to sum up, I want to make a loop that repeatedly accesses a site on Tor, checks something on that site and then restarts Tor with a new identity.
如果任何人可以给我一些指导,告诉我可以使用,这将是非常感谢。
If anyone could give me some guidance and tell me what I can use, it would be much appreciated. I have the time and patience to learn, so anything works really.
推荐答案
这里有使用PHP和Python 3来完成什么的例子你要。
Here are examples using PHP and Python 3 to accomplish what you want. They're simple starting points for making requests over Tor and changing your identity on demand.
PHP示例使用与控制器进行通信并包装cURL。 https://stem.torproject.org/ =nofollow noreferrer> stem 与控制器进行通信,通过Tor的SOCKS代理发送请求。
The Python example uses stem to communicate with the controller and Requests for sending requests over Tor's SOCKS proxy.
这些示例假设您已经具有Tor工作, SocksPort 设置为9050,并将 ControlPort 设置为9051(使用cookie身份验证工作)或控制器密码 password 。
The examples assume you have Tor working already and the SocksPort set to 9050, and the ControlPort set to 9051 with cookie authentication working, or a controller password of password.
- 安装以安装TorUtils软件包(您也可以下载zipball并解压缩)
- 一旦编译器正常工作,请从项目目录运行 composer require dapphp / torutils 下载并安装依赖项
- Install Composer to install the TorUtils package (you can also download the zipball and extract)
- Once composer is working, run composer require dapphp/torutils from your project directory to download and install dependencies
<?php use Dapphp\TorUtils\ControlClient; use Dapphp\TorUtils\TorCurlWrapper; require_once 'vendor/autoload.php'; // composer autoloader // include TorUtils/src/ControlClient.php and TorUtils/src/TorCurlWrapper.php if using without composer $controller = new ControlClient; // get a new controller object try { $controller->connect('127.0.0.1', 9051); // connect to Tor controller on localhost:9051 $controller->authenticate('password'); // attempt to authenticate using "password" as password } catch (\Exception $ex) { die("Failed to open connection to Tor controller. Reason: " . $ex->getMessage() . "\n"); } // issue 10 requests, changing identity after each request for ($i = 0; $i < 10; ++$i) { try { $curl = new TorCurlWrapper('127.0.0.1', 9050); // connect to Tor SOCKS proxy on localhost:9050 $curl->httpGet('https://drew-phillips.com/ip-info/'); // issue request $body = strip_tags($curl->getResponseBody()); if (preg_match('/Using Tor:\s*Yes/i', $body)) { echo "You appear to be using Tor successfully. "; } else { echo "Proxy worked but this Tor IP is not known. "; } if (preg_match('/IP Address:\s*(\d+\.\d+\.\d+\.\d+)/i', $body, $ip)) { echo "Source IP = {$ip[1]}\n"; } else { echo "Couldn't determine IP!\n"; } } catch (\Exception $ex) { echo "HTTP request failed! " . $ex->getMessage() . "\n"; } // TODO: issue more requests as needed here echo "\n"; sleep(10); try { // send signal to controller to request new identity (IP) $controller->signal(ControlClient::SIGNAL_NEWNYM); } catch (\Exception $ex) { echo "Failed to issue NEWNYM signal: " . $ex->getMessage() . "\n"; } }
Python 3
设置
此示例使用Python 3并假设您已启动并运行Python解释器,并安装以下软件包:请求,请求[socks] , socks , urllib3 ,,。
在Debian / Ubuntu上: -H pip3安装请求请求[socks] socks urllib3 stem
On Debian/Ubuntu: sudo -H pip3 install requests requests[socks] socks urllib3 stem
#!/usr/bin/env python3 import requests from stem.control import Controller, Signal import time import sys import re # specify Tor's SOCKS proxy for http and https requests proxies = { 'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050', } try: controller = Controller.from_port(9051) # try to connect to controller at localhost:9051 except stem.SocketError as exc: print("Unable to connect to tor on port 9051: %s" % exc) sys.exit(1) try: controller.authenticate('password') # try to authenticate with password "password" except stem.connection.PasswordAuthFailed: print("Unable to authenticate, password is incorrect") sys.exit(1) # issue 10 requests, changing identity after each request for i in range(1,10): # issue request, passing proxies to request r = requests.get('https://drew-phillips.com/ip-info/', proxies=proxies) #print(r.text) m = re.search('<dt>Using Tor:</dt><dd><span[^>]*>Yes', r.text) if m: print("You appear to be using Tor successfully. ", end="") else: print("Proxy worked but this Tor IP is not known. ", end="") m = re.search('<dt>IP Address:</dt><dd>(\d+\.\d+\.\d+\.\d+)</dd>', r.text) if m: print("Source IP = %s" % m.groups(1)) else: print("Failed to scrape IP from page") try: # send signal to controller to request new identity (IP) controller.signal(Signal.NEWNYM) except Exception as ex: print("NEWNYM failed: %s" % ex) time.sleep(10)
这篇关于试图自动化Tor在网站上做某事,并改变身份每次。需要一些指导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!