开发者

Perl Socket Connection Check

开发者 https://www.devze.com 2023-02-06 10:02 出处:网络
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.

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', Timeout => 5 ) or die @$;

            $sock4 = pack( "CCS", 4, 1, 80 );

            print $look $sock4;

            read( $look, $recv, 10 );

            ( $empty, $granted, $junk ) = unpack( "C C C6", $recv );

            if( $granted == 0x5A )
            {
                    print " Yes\n";
            }
            else
   开发者_开发技巧         {
                    print " No\n";
            }
...


There's a typo. @$ should really be $@.

To get rid of the "possible typo" messages and since $empty and $junk seem to be unused in your code, write:

my @result = unpack("C C C6", $recv);

if ($result[1] == 0x5A) {
# ...
}


Just a side note : I think you are thinking of $@, instead of @$. You need to enclose the code in an

eval { ... };

construction. See:

my $look;
eval { $look = IO::Socket::INET->new( PeerAddr => $_, Proto => 'tcp', Timeout => 5 ) };

if ($@) {
   do_something_with($@);
}

Granted, that doesn't answer the original question :)


The error message means that your parameter value for PeerAddr in the IO::Socket::INET->new call is invalid.

The constructor expects the PeerAddr value to be a hostname or an IP address (nnn.nnn.nnn.nnn). Check the contents of $_ and I bet you'll find something different.

0

精彩评论

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