perl - 为什么 Perl 可能允许使用 TOR 而不是 https 的 http 网站?

标签 perl https tor

如果它是 https 站点,我在使用 perl 通过 TOR 访问网站时遇到困难,但如果它是 http 站点则不会。

#!/usr/bin/perl
use strict;

use WWW::Mechanize;
use LWP::Protocol::socks;
use LWP::Protocol::https;
use utf8;

my $mech = WWW::Mechanize->new(timeout => 60*5);
$mech->proxy(['http', 'https'], 'socks://localhost:9150');
$mech->get("https://www.google.com");

我收到错误消息:Error GETing https://www.google.com :状态读取失败:第 10 行错误的文件描述符”,其中第 i10 行是程序的最后一行。

在TOR浏览器中,可以成功查看:“https://www.google.com”,端口为9150。
我正在使用 ActivePerl 5.16.2;瓦达利亚 0.2.21 和 Tor 0.2.3.25。
我有一台 Windows 机器,我的主要互联网浏览器是 Mozilla。

我尝试使用以下命令安装软件包:
cpan LWP::UserAgent
ppm install LWP::Protocol::https
cpan LWP::Protocol::https
ppm install LWP::Protocol::socks
cpan LWP::Protocol::socks
ppm install Mozilla::CA
ppm install IO::Socket::SSL
ppm install Crypt::SSLeay
cpan Crypt::SSLeay

感谢您的任何帮助!请让我知道我是否可以提供更多信息。

最佳答案

前段时间,我找到了使用 WWW::Curl::Easy 使用 Tor 浏览 https 站点的方法来获取这些类型的站点,因为使用 LWP 我发现了同样的问题。
之后,我将所有 html 保存在文件中,并使用 WWW::Mechanzie 或 HTML::TreeBuilder 解析它们。

如果您希望与站点进行更多交互,例如 post forms 等。此解决方案可能更乏味,因为您需要与 curl 进行交互。
package Curl; use warnings; use WWW::Curl::Easy; use WWW::UserAgent::Random; my $curl = WWW::Curl::Easy->new; my $useragent = rand_ua("browsers"); my $host = 'localhost'; my $port = '9070'; my $timeout = '20'; my $connectTimeOut= '20'; &init; sub get { my $url = shift; $curl->setopt(CURLOPT_URL, $url); my $response_body; $curl->setopt(CURLOPT_WRITEDATA,\$response_body); my $retcode = $curl->perform; if ($retcode == 0) { print("Transfer went ok Http::Code = ".$curl->strerror($retcode)."\n"); my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE); # judge result and next action based on $response_code return \$response_body; } else { # Error code, type of error, error message print("An error happened: $retcode ".$curl->strerror($retcode)." ".$curl->errbuf."\n"); return 0; } } sub init { #setejem el proxy $curl->setopt(CURLOPT_PROXY,"$host:".$port); $curl->setopt(CURLOPT_PROXYTYPE,CURLPROXY_SOCKS4); #posem les altres dades $curl->setopt(CURLOPT_USERAGENT, $useragent); $curl->setopt(CURLOPT_CONNECTTIMEOUT, $connectTimeOut); $curl->setopt(CURLOPT_TIMEOUT, $timeout); $curl->setopt(CURLOPT_SSL_VERIFYPEER,0); $curl->setopt(CURLOPT_HEADER,0); }
希望能帮到你!

关于perl - 为什么 Perl 可能允许使用 TOR 而不是 https 的 http 网站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15551728/

相关文章:

tor - 如何更改 TOR 链中的默认节点数?

perl - "ladder sub {...}"在 perl 中是什么意思?

perl - 我可以请一个 ArrayOutOfBoundsException 吗?

https - Airflow 中用于 HTTPS 的 HttpOperator 或 HttpHook

PHP SoapClient SSL 连接超时错误

perl - 如何通过 perl 在非 GUI 服务器上使用 Tor 网络

c - 是否可以在未安装 TOR 的情况下连接到 TOR?

perl - 如何打印v-string?

perl - 如何在运行的 Perl session 中编译 Perl 脚本?

外部可访问的 Tomcat Manager 中的安全风险