sammy89 has asked for the wisdom of the Perl Monks concerning the following question:

I've been trying to debug this perl issue for awhile but had made no head way. what I'm trying to do is determain if the connection is a socks4/5 connection.

# ./pctest.pl
Name "main::junk" used only once: possible typo at ./pctest.pl line 60.
Name "main::empty" used only once: possible typo at ./pctest.pl line 60.
IO::Socket::INET: Bad hostname 'C1(X' ...propagated at ./pctest.pl line 52.
I've also had this error (before i added or die @$; at the end):


Can't use an undefined value as a symbol reference at ./pctest.pl line 56.

... $look = IO::Socket::INET->new( PeerAddr => $_, Proto => 'tcp', Timeo +ut => 5 ) or die @$;<br> <br> $sock4 = pack( "CCS", 4, 1, 80 );<br> <br> print $look $sock4;<br> <br> read( $look, $recv, 10 );<br> <br> ( $empty, $granted, $junk ) = unpack( "C C C6", $recv );<b +r> <br> if( $granted == 0x5A )<br> {<br> print " Yes\n";<br> }<br> else<br> {<br> print " No\n";<br> }<br> ...<br>

Replies are listed 'Best First'.
Re: Perl Socket Connection Check
by tilly (Archbishop) on Jan 26, 2011 at 07:04 UTC
    Are you trying to write a server or a client?

    If you're trying to write a server, the client should tell you in the first byte whether it is trying to talk SOCKS 4 or 5.

    If you're writing a client, see Net::SOCKS. You should specify the lowest possible version that has all of the features that you need.

Re: Perl Socket Connection Check
by Khen1950fx (Canon) on Jan 26, 2011 at 07:55 UTC
    To check for socks, use Net::Proxy::Type.
    #!/usr/bin/perl use strict; use warnings; use Net::Proxy::Type ':types'; my $proxytype = Net::Proxy::Type->new(); my $proxy = 'remotehost'; if ($proxytype->is_socks4($proxy)) { warn "$proxy is a socks4 proxy", "\n"; } elsif ($proxytype->is_socks5($proxy)) { warn "$proxy is a socks5 proxy", "\n"; } else { warn "$proxy is unknown", "\n"; }