开发者

Using socks5 proxy with Net::SMTP

开发者 https://www.devze.com 2023-01-07 01:22 出处:网络
I开发者_如何学C 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?I figured it out, but it includes hack that may or ma

I开发者_如何学C 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?


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...
0

精彩评论

暂无评论...
验证码 换一张
取 消