在 Net::SMTP 中使用 socks5 代理 [英] Using socks5 proxy with Net::SMTP

查看:162
本文介绍了在 Net::SMTP 中使用 socks5 代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 Net::SMTP 与动态袜子代理一起使用.IO::Socket::Socks 知道socks 但它应该如何与net::smtp 一起使用?

I would like to use Net::SMTP with dynamic socks proxy. IO::Socket::Socks is aware of socks but how it should be used with net::smtp?

推荐答案

我想通了,但它包含的 hack 可能适用于 Net::SMTP 的未来版本,也可能不适用:

I figured it out, but it includes hack that may or may not work with future version of Net::SMTP :

use Net::SMTP;
use Net::SOCKS;
my $socks = new Net::SOCKS(socks_addr=>$shost,socks_port=>$sport, protocol_version=>5) or die $!; 
my $socksfd = $socks->connect(peer_addr=>$smtp_server,peer_port=>25);
if(!$socksfd){
    die "Connection to SOCKS failed";
}
my $smtp = Net::SMTP->new_from_fd($socksfd->fileno, 'r+' ) or die $!;

#HACK: there is "220 host.domain.net" line we must read otherwise Net::SMTP would not work!
$smtp->getline();

$smtp->hello("localhost") or die $smtp->message();
#from here Net::SMTP business as usual...

这篇关于在 Net::SMTP 中使用 socks5 代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆