AnyEvent-SOCKS-Client
view release on metacpan or search on metacpan
lib/AnyEvent/SOCKS/Client.pm view on Meta::CPAN
AUTH_GTFO => 255,
CMD_CONNECT => 1 ,
CMD_BIND => 2,
CMD_UDP_ASSOC => 3,
};
sub _parse_uri{
my $re = qr!socks(4|4a|5)://(?:([^\s:]+):([^\s@]*)@)?(\[[0-9a-f:.]+\]|[^\s:]+):(\d+)!i ;
if( $_[0] =~ m/$re/gi ){
my $p = {v => $1, login => $2, password => $3, host => $4, port => $5};
$p->{host} =~ s/^\[|\]$//g;
return $p;
}
undef ;
}
# returns tcp_connect compatible function
sub tcp_connect_via{
my(@chain) = @_ ;
unless( @chain ){
lib/AnyEvent/SOCKS/Client.pm view on Meta::CPAN
return;
}
$self->socks_connect_done( format_ipv4( $dst_ip ), $dst_port );
});
}
sub handshake{
my( $self ) = @_;
my $that = $self->{chain}->[0] ;
my @auth_methods = 0 ;
if($that->{login} and $that->{password}){
push @auth_methods, AUTH_LOGIN ;
}
$self->{hd}->push_write(
pack('CC', 5, scalar @auth_methods ) . join( "", map( pack( 'C', $_ ), @auth_methods ))
);
$self->{hd}->push_read( chunk => 2 , sub{
my $method = unpack( 'xC', $_[1] );
AE::log "debug" => "Server want auth method $method" ;
if($method == AUTH_GTFO ){
AE::log "error" => "Server: no suitable auth method";
lib/AnyEvent/SOCKS/Client.pm view on Meta::CPAN
}
else {
$self->connect_cmd ;
}
});
}
sub auth{
my( $self, $method ) = @_;
my $that = $self->{chain}->[0] ;
if( $method == AUTH_LOGIN and $that->{login} and $that->{password}){
$self->{hd}->push_write(
pack('CC', 5, length $that->{login} ) . $that->{login}
. pack('C', length $that->{password}) . $that->{password}
);
$self->{hd}->push_read( chunk => 2, sub{
my $status = unpack('xC', $_[1]) ;
if( $status == 0 ){
$self->connect_cmd ;
return ;
}
AE::log "error" => "Bad login or password";
});
return ;
}
AE::log "error" => "Auth method $method not implemented!";
}
sub connect_cmd{
my( $self ) = @_ ;
my $next = $self->{chain}->[1] ;
my( $host, $port ) = $next
( run in 0.492 second using v1.01-cache-2.11-cpan-49f99fa48dc )