如何解决袜子服务器和客户端
我有以下袜子服务器
my $socks_server = IO::Socket::Socks->new(
ProxyAddr => "localhost",ProxyPort => 8000,Listen => 1,) or die "socket error";
while(1) {
my $client = $socks_server->accept();
print $client;
unless ($client) {
print "ERROR:";
next;
}
}
以及以下的Socks Client
use strict;
use warnings;
use IO::Socket::Socks;
my $socks_client = IO::Socket::Socks->new(
ProxyAddr => "localhost",ProxyPort => "8000",) or die $SOCKS_ERROR;
print $socks_client "foo\n";
$socks_client->close();
Socks客户端打印“ foo \ n”,如何在接收到Socks服务器后将其打印到控制台?
解决方法
以下代码仅用于演示目的,为简单起见,关闭了身份验证。
该代码基于IO::Socket::Socks的文件加密
server.pl
的代码use strict;
use warnings;
use feature 'say';
use IO::Socket::Socks ':constants';
my $SOCKS_ERROR = 'Error: SOCKS';
my $socks_server = IO::Socket::Socks->new(
ProxyAddr => "localhost",ProxyPort => 8000,Listen => 1,UserAuth => \&auth,RequireAuth => 0
) or die $SOCKS_ERROR;
while(1) {
my $client = $socks_server->accept();
unless ($client) {
print "ERROR: $SOCKS_ERROR\n";
next;
}
my $command = $client->command();
if ($command->[0] == CMD_CONNECT) {
# Handle the CONNECT
$client->command_reply(REPLY_SUCCESS,'localhost',8000);
}
print while <$client>;
$client->close();
}
sub auth {
my ($user,$pass) = @_;
return 1 if $user eq "foo" && $pass eq "bar";
return 0;
}
client.pl
的代码use strict;
use warnings;
use feature 'say';
use IO::Socket::Socks;
my $socks_client = IO::Socket::Socks->new(
ProxyAddr => "localhost",ProxyPort => "8000",ConnectAddr => "localhost",ConnectPort => "8022",) or die $SOCKS_ERROR;
print $socks_client $_ for <DATA>;
$socks_client->close();
__DATA__
-----------------------------------------------
This a test message sent from remote client for
SOCKS demonstration code.
Enjoy your day.
server.pl 端的输出
C:\....\examples\socks_server.pl
-----------------------------------------------
This a test message sent from remote client for
SOCKS demonstration code.
Enjoy your day.
client.pl 端的输出
C:\...\examples\socks_client.pl
C:\...>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。