我真的需要一些帮助来自动化Tor在站点上执行某些操作(在这种情况下,检查轮询上的内容)然后使用新标识重新启动Tor。我从来没有做过任何与此有关的事情。我只是很清楚HTML,CSS和JS。
现在,总而言之,我想创建一个循环,重复访问Tor上的站点,检查该站点上的某些内容,然后使用新标识重新启动Tor。
如果有人能给我一些指导并告诉我我可以使用什么,我将不胜感激。我有时间和耐心去学习,所以一切都有效。
答案 0 :(得分:2)
以下是使用PHP和Python 3完成所需内容的示例。他们是通过Tor提出请求并根据需要更改您的身份的简单起点。
PHP示例使用TorUtils与控制器通信并通过Tor包装cURL。
Python示例使用stem与控制器进行通信,使用Requests通过Tor的SOCKS代理发送请求。
示例假设您已经使用Tor并且+---------+------+--------+----------+
| prod_id | name | value1 | value2 |
+---------+------+--------+----------+
| 1105 | aat | | |
| 1108 | bbv |banana |apple |
| 1111 | ccq | | |
| 1116 | dde |cucumber|pineapple |
| 1123 | iir |orange |melon |
| 1125 | jjm | | |
+---------+------+--------+----------+
设置为9050,并且SocksPort
设置为9051且Cookie身份验证正常,或者控制器密码为ControlPort
。
password
以下载并安装依赖项composer require dapphp/torutils
此示例使用Python 3并假设您已启动并运行Python解释器并安装了以下软件包:<?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";
}
}
,requests
,requests[socks]
,socks
,{ {1}}。
在Debian / Ubuntu上:urllib3
stem