<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
#Connection-Tracker-0.1.pl
#This script can be used to find the no of connections to each port on the basis of type(SYN,TIME_WAIT,ESTABLISHED)
#Sujai Sojan&lt;sujai@logicsupport.com&gt;
$VERSION = 0.1;
print "Port:";
$Portin=&lt;STDIN&gt;;
print "State(0.TIME_WAIT,1.ESTABLISHED,2.SYN):";
$Statein=&lt;STDIN&gt;;
@states=("TIME_WAIT","ESTABLISHED","SYN");
print "No of minimum connections:";
$Nocon=&lt;STDIN&gt;;
%seen = ();
@netstat=`netstat -antu`;
foreach (@netstat)
  {

   if($_ =~ /(\d*)\.(\d*)\.(\d*).(\d*)/)
    {
      
      ($Proto,$Recv,$Send,$Local,$Foreign,$State)=split(' ',$_,6);
      ($Ipaddress,$Port)=split(':',$Local,2);
      if(($Port == $Portin) &amp;&amp; ($Foreign !~ /0\.0\.0\.0/)&amp;&amp; ($Foreign =~ /(\d*)\.(\d*)\.(\d*).(\d*)/) &amp;&amp; ($State == $states[$Statein]))
 
        {
         ($Ipaddress,$Port)=split(':',$Foreign,2);
         $seen{$Ipaddress} ++;
        }
    
    }

  }

print "Ipaddress : No of Connections";

sub hashValueAscendingNum {
   $seen{$a} &lt;=&gt; $seen{$b};
}
foreach $key(sort hashValueAscendingNum (keys (%seen)))
 {
  if($seen{$key} gt $Nocon)
  {
   print "$key\t\t\t $seen{$key}\n";
  }
 }


=head1 NAME

Connection-Tracker

=head1 AUTHOR
Sujai Sojan &lt;sujai@logicsupport.com&gt;

=head1 DESCRIPTION

This script can be used to find the no of connections to each port on the basis of type(SYN,TIME_WAIT,ESTABLISHED)



=pod OSNAMES

Linux

=pod SCRIPT CATEGORIES

Unix/System_administration

=cut


</pre></body></html>