Skip to content

Patch 1 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions tcp-proxy2.pl
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/usr/bin/perl
#
# Peteris Krumins ([email protected])
# http://www.catonmat.net -- good coders code, great reuse
#
#
# Written for the article "A TCP Proxy in Perl":
#
# http://catonmat.net/blog/perl-tcp-proxy
#

#!/usr/bin/perl
#
# Peteris Krumins ([email protected])
# http://www.catonmat.net -- good coders code, great reuse
# Minor Improve by Tche333
#
# Written for the article "A TCP Proxy in Perl":
#
# http://catonmat.net/blog/perl-tcp-proxy
#
use warnings;
use strict;

use IO::Socket::INET;
use IO::Select;

my @allowed_ips = ('all', '10.10.10.5');
#my @allowed_ips = ('all', '10.10.10.5');
my @allowed_ips = ('10.10.10.5');
my $ioset = IO::Select->new;
my %socket_map;

Expand All @@ -24,6 +24,7 @@
sub new_conn {
my ($host, $port) = @_;
return IO::Socket::INET->new(
Type => SOCK_STREAM,
PeerAddr => $host,
PeerPort => $port
) || die "Unable to connect to $host:$port: $!";
Expand All @@ -33,6 +34,8 @@ sub new_server {
my ($host, $port) = @_;
my $server = IO::Socket::INET->new(
LocalAddr => $host,
# Proto => "tcp",
Type => SOCK_STREAM,
LocalPort => $port,
ReuseAddr => 1,
Listen => 100
Expand All @@ -55,6 +58,8 @@ sub new_connection {
print "Connection from $client_ip accepted.\n" if $debug;

my $remote = new_conn($remote_host, $remote_port);
print "Connecting to $remote_host:$remote_port.\n" if $debug;

$ioset->add($client);
$ioset->add($remote);

Expand Down Expand Up @@ -119,4 +124,3 @@ sub client_allowed {
}
}
}