Re: Current users
I believe you want netstat -M. Unfortunately, it only works with
ipchains. For iptables, you need to look at /proc/net/ip_conntrack.
I've written a [probably poorly constructed ;)] small perl script to
display this information in a format similar to netstat -M for iptables
systems. It is attached to this message.
On Tue, 2002-07-09 at 14:19, Leonardo Custodio wrote:
> How can i get the description (IP, uptime, ..) of the current users using
> the Masquerade connection on my machine?
>
> Thank you,
> Leonardo Custodio
> Debian GNU/Linux 2.2r6
> http://sites.uol.com.br/kromagg
>
>
>
> --
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
#!/usr/bin/perl -w
use Socket;
unless(@ARGV) {
$ARGV[0] = 0;
}
open(INFO, "/proc/net/ip_conntrack") or die("$!");
my @info = <INFO>;
close(INFO);
printf("%s\t%s\t\t%-27s%-27s%s\n", "Proto", "Time", "Source", "Destination", "State");
foreach(@info) {
if(/^([^ ]+)\s+\d+ (\d+) ?(\w*) src=([^ ]+) dst=([^ ]+) sport=([^ ]+) dport=([^ ]+).*$/) {
if($ARGV[0] eq "-n") {
$src = $4;
$dst = $5;
} else {
$src = gethostbyaddr(inet_aton($4), AF_INET) or $src = $4;
$dst = gethostbyaddr(inet_aton($5), AF_INET) or $dst = $5;
}
$srcnum = 7;
$dstnum = 7;
if ((20 - length($src)) > 0) {
$srcnum = 27 - length($src);
}
if ((20 - length($dst)) > 0) {
$dstnum = 27 - length($dst);
}
print "$1\t";
print mytime($2) . "\t";
printf("%.20s", "$src");
printf("%-${srcnum}s", ":$6 ");
printf("%.20s", "$dst");
printf("%-${dstnum}s", ":$7 ");
print "$3\n";
}
}
sub mytime {
my ($seconds) = @_;
my $hours = "00";
my $minutes = "00";
if($seconds >= 3600) {
my $i = $seconds / 3600;
if($i =~ /^([0-9]+)/) {
$hours = $1;
}
my $newseconds = $seconds - ($hours * 3600);
$seconds = $newseconds;
} if ($seconds >= 60) {
my $i = $seconds / 60;
if($i =~ /^([0-9]+)/) {
$minutes = $1;
}
my $newseconds = $seconds - ($minutes * 60);
$seconds = $newseconds;
}
my $final = sprintf("%2.2d:%2.2d:%2.2d", $hours, $minutes, $seconds);
undef($hours);
undef($seconds);
undef($minutes);
return $final;
}
Reply to: