Perl 套接字连接检查

发布于 2024-10-14 18:42:53 字数 978 浏览 1 评论 0原文

我已经尝试调试这个 perl 问题有一段时间了,但没有取得进展。我想要做的是确定连接是否是socks4/5 连接。

# ./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.

我也遇到过这个错误(在我添加或死亡@$;之前):

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";
            }
...

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";
            }
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧人九事 2024-10-21 18:42:53

有一个错字。 @$ 实际上应该是 $@

要消除“可能的拼写错误”消息,并且由于 $empty$junk 似乎在代码中未使用,请编写:

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

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

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) {
# ...
}
始于初秋 2024-10-21 18:42:53

只是旁注:我认为您正在考虑 $@,而不是 @$。您需要将代码包含在

eval { ... };

构造中。请参阅:

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

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

当然,这并没有回答原来的问题:)

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 :)

谢绝鈎搭 2024-10-21 18:42:53

该错误消息意味着 IO::Socket::INET->new 调用中 PeerAddr 的参数值无效。

构造函数期望 PeerAddr 值为主机名或 IP 地址 (nnn.nnn.nnn.nnn)。检查 $_ 的内容,我打赌你会发现一些不同的东西。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文