AnyEvent-SOCKS-Client

 view release on metacpan or  search on metacpan

lib/AnyEvent/SOCKS/Client.pm  view on Meta::CPAN

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
        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

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
                        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

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
                }
                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.234 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )