I have already posted it to comp.lang.perl.misc. Reposting here as it is, probably for a wider audience.
-----------------------------------------
I am searching for a port forwarding package in perl, some thing like plugproxy in java(http://www.bbzzdd.com/plugproxy). My basic requirement is to have a platform independent snooping tool between two servers. The servers may be on the same m/c. So we need to replace currently used ipthreal/iptrace.
I was wondering if there exists any package with functionality similar to plugproxy. IPChains::PortFW seemed promising. But I couldn't install it on Solaris. The documentation also clearly mentions it's for linux.
In perl cook-book first edition chapter 17.18 there is a program which probably would serve our purpose with some modification. Another option is to make a perl wrapper over plugproxy and use it.
Could somebody point me to a module already exists or being writen which fits into this before we reinvent the wheel?
Thanks and regards,
Debashish.
A short search on CPAN reveals Stephanie Wehners modules, most important Net::ProxyMod.
Another interesting suite of modules is tne Net::PCap suite of modules (also Net::PCapUtils), which gives you access to packet capture and alteration functions of libpcap.
I am searching for a port forwarding package in perl
Why Perl? (When all you have is a hammer, all your problems start to look like nails).
My basic requirement is to have a platform independent snooping tool between two servers
It sounds to me you want something like Socat. (The site seems to be down at the moment, although it does rate a mention on Freshmeat). Otherwise search around on the web.
socat will do all you want and more. Take the time to learn how to use it, and it will reward you greatly.
- another intruder with the mooring of the heat of the Perl
#!perl -w
# usage: portforward configfile
# configfile has lines like this:
#18025 mail.messagingengine.com:25
#18110 mail.messagingengine.com:110
#where 18025 is the TCP port on the local machine and
# mail.messagingengine.com:25
#is where that port is forwarded to.
use Socket;
use IO::Socket;
use IO::Select;
use strict;
$| = 1;
my %ports;
my $listen_set = IO::Select->new();
$SIG{CHLD} = 'IGNORE';
while (<>) {
chomp;
my ($localport, $remotehost) = split;
$ports{$localport} = $remotehost;
print "config $localport -> $remotehost\n";
my $socklisten = IO::Socket::INET->new(LocalPort => $localport,
Listen => 2,
Reuse => 1,
Proto => 'tcp')
or die "Cannot open sock on $localport: $!\n";
$listen_set->add($socklisten);
}
my @ready;
print "Parent ready to accept\n";
while (1) {
@ready = $listen_set->can_read;
for my $socklisten (@ready) {
my $socklocal = $socklisten->accept;
if (defined $socklocal) {
my ($port, $myaddr) = sockaddr_in(getsockname($socklisten));
print "accepted on $port\n";
my $remotehost = $ports{$port};
if (! defined($remotehost)) {
print "Internal error on port $port\n";
die;
}
if (fork()) {
close($socklocal);
} else {
close($socklisten);
my $sockremote = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "$remotehost",
Timeout => 30,
)
or die "cannot create socketremote($remotehost): $!\n";
my $buf= ' 'x4096;
if (fork()) {
my $sent = 0;
while (sysread($socklocal, $buf, 4096)) {
print $sockremote $buf;
$sent += length($buf);
}
# print "Total bytes sent $sent\n";
} else {
my $rcvd = 0;
while(sysread($sockremote, $buf, 4096)) {
print $socklocal $buf;
$rcvd += length($buf);
}
# print "Total bytes rcvd: $rcvd\n";
}
exit(0);
}
}
}
}
print "End of parent: $!\n";
__END__
I don't know of any network sniffers written in Perl. It should be possible to use libpcap through Net::Pcap. But ethereal or tcpdump would work better.
perlmonks.org content © perlmonks.org and Anonymous Monk, borisz, Corion, deba, grinder, iburrell, Thelonius
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03