#!/usr/bin/perl # # Nom : iptables-watcher.sh # Description : Affiche les connections actives via ip_conntrack # OS : Debian # Requires : iptables, ip_conntrack # Licence : GPL # Version : 0.0.2 # Author : Adrien Pujol # Web site : http://www.crashdump.fr/ # $arg=$ARGV[0]; if ($arg ne "-x") { exec "watch -n 1 $0 -x"; } printf "Proto\tTimeout\t Src \t Dst \tStatus\n"; open F, "cat /proc/net/ip_conntrack |" || die "Impossible d'ouvrir /proc/net/ip_conntrack"; while () { $status=""; if ($_=~/^tcp/ || $_=~/^udp/) { $_ =~ /\[(\S+)\]/; $status = $1; $_ =~ /^(\S+)/; $proto = $1; $_ =~ /\S+\s+\d+\s+(\d+)/; $n = $1; $_ =~ /src=(\d+\.\d+\.\d+\.\d+)/; $src = $1; $_ =~ /dst=(\d+\.\d+\.\d+\.\d+)/; $dst = $1; $_ =~ /sport=(\d+)/; $sport = $1; $_ =~ /dport=(\d+)/; $dport = $1; } printf "%s\t%d\t%15s:%-5s\t%15s:%-5s\t%s\n",$proto,$n,$src,$sport,$dst,$dport,$status; } close F;