Sponsored Content
Full Discussion: Count no of netstat states
Top Forums Shell Programming and Scripting Count no of netstat states Post 302911138 by bigearsbilly on Wednesday 30th of July 2014 10:59:41 AM
Old 07-30-2014
Here is my own little concoction I use for such things.
Produces output like:
Code:
=====================================
host                    total   FIN_WAIT2 ESTABLISHED
192.168.1.115   |           1           0           1
192.168.1.32    |           1           0           1
86.8.240.6      |           7           6           1
total           |           9           6           3


Code:
#!/usr//bin/perl 

use strict;
my ($Proto, $Recv, $Send, $Local, $Foreign, $State);
my ($local, $foreign, $f_port, $l_port);
my $db = {};
my @STATES;
my $stats = {};
our $verbose = 1;


open NETSTAT,  "netstat -nt |" or die "netstat:$!\n"; 

my $headers = my $h = 2;
<NETSTAT> while ($h--);

LOOP:
while (<NETSTAT>) {

    ($Proto, $Recv, $Send, $Local, $Foreign, $State) = split;

    foreach my $grep (@ARGV) {
        next LOOP unless /$grep/;
    }

    print if $verbose ;

    ($foreign, $f_port) = split ':', $Foreign;
    ($local, $l_port) = split ':', $Local;

    $stats->{$State}++;

    $db->{$foreign}->{connections}++ ;
    $db->{$foreign}->{states}->{$State}++;
    $db->{total}->{connections}++ ;
    $db->{total}->{states}->{$State}++;
}

@STATES = (keys %$stats);
printf "=====================================\n";
printf "%-16s %12s", "host", "total";
map { printf "%12s", $_ } @STATES;
print "\n";

foreach my $h (sort keys %$db) {
    printf "%-16s|", $h;
    printf "%12d",  $db->{$h}->{connections};
    foreach my $s (@STATES) {
        my $state = $db->{$h}->{states}->{$s} +  0; 
        printf "%12d",  $state;
    }
    print "\n";

}

This User Gave Thanks to bigearsbilly For This Post:
 

8 More Discussions You Might Find Interesting

1. IP Networking

laymens terms for netstat states

Ok, I've read the manpages on netstat and it gives a good description of the state values such as CLOSE_WAIT, ESTABLISHED, SYN_RECEIVED, etc.. Can someone give me real world situations where you would get these states. LIke for example if I got SYN_RECEIVED what possible situations would be the... (1 Reply)
Discussion started by: eloquent99
1 Replies

2. IP Networking

netstat - possible reasons for high IP count ???

One of my servers started getting heavily loaded a few weeks ago for a few hours, so I did some studying and wrote a script to use netstat to get the IP addresses connected and the count. I put a new chain in iptables and if an IP is using more than 40 connections, it gets added to that chain which... (3 Replies)
Discussion started by: PWSwebmaster
3 Replies

3. Solaris

meaning of states in sun clusters

Hi Everybody, As I am new to Sun Clusters, Please help me what is "online but not monitored" state of resources and "online - service is online" in status message. Thank you. (1 Reply)
Discussion started by: mayahari
1 Replies

4. UNIX for Advanced & Expert Users

cpufreq directory not present. How to change governor for P states in such a case

One node in my cluster is using ondemand governor which is specified in the directory /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor .. Scaling_governor allows us to choose the governor of our choice . But this sub-directory is absent in the other node of the cluster . How do I change... (0 Replies)
Discussion started by: vishwamitra
0 Replies

5. UNIX for Advanced & Expert Users

Unix process states

I am trying to write my own Unix compliant (SUSv4) OS - Just a hobby OS, nothing serious. While going through the standard, I couldn't find any explicit information on process states. What I could find was (excluding the real-time considerations)- From this it can be inferred that the... (2 Replies)
Discussion started by: tinkerbeast
2 Replies

6. UNIX and Linux Applications

Where can I find UNIX training course in the United States?

Hi guys, Can you help me please to find an appropriate course of UNIX in the United States. Also, can you provide me some information about the schools or institutes that offer it in the U.S. Thanks, (0 Replies)
Discussion started by: Malik Dera
0 Replies

7. Hardware

Hyperthreaded virtual cores, different C-States?

turbostat reports C-states of all CPU cores, and includes entries for each hyper-threaded core as well. Often enough the two logical cores on a single physical core will list different C state percentages. Does that make any sense? Is this reporting the c-states of the few duplicated parts... (8 Replies)
Discussion started by: agentrnge
8 Replies

8. Shell Programming and Scripting

Ps command showing different states for same process

I am using HP-UX,KSH $ jobs -l + 19377 Running nohup ksh cat_Duplicate_Records_Removal.ksh </dev/null >/dev/null 2>&1 & $ ps -p 19377 -fl F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME COMD 401 S catmgr 19377 19491 ... (1 Reply)
Discussion started by: TomG
1 Replies
Alzabo::ForeignKey(3pm) 				User Contributed Perl Documentation				   Alzabo::ForeignKey(3pm)

NAME
Alzabo::ForeignKey - Foreign key (relation) objects SYNOPSIS
use Alzabo::ForeignKey; foreach my $fk ($table->foreign_keys) { print $fk->cardinality; } DESCRIPTION
A foreign key is an object defined by several properties. It represents a relationship from a column or columns in one table to a column or columns in another table. This relationship is defined by its cardinality (one to one, one to many, or many to one) and its dependencies (whether or not table X is dependent on table Y, and vice versa). Many to many relationships are not allowed. However, you may indicate such a relationship when using the Alzabo::Create::Schema->add_rela- tion method method, and it will create the necessary intermediate linking table for you. METHODS
table_from table_to Returns the relevant "Alzabo::Table" object. columns_from columns_to Returns the relevant "Alzabo::Column" object(s) for the property as an array. column_pairs Returns an array of array references. The references are to two column array of "Alzabo::Column" objects. These two columns correspond in the tables being linked together. cardinality Returns a two element array containing the two portions of the cardinality of the relationship. Each portion will be either '1' or 'n'. from_is_dependent to_is_dependent Returns a boolean value indicating whether there is a dependency from one table to the other. is_one_to_one is_one_to_many is_many_to_one Returns a boolean value indicating what kind of relationship the object represents. is_same_relationship_as ($fk) Given a foreign key object, this returns true if the two objects represent the same relationship. However, the two objects may represent the same relationship from different table's points of view. id Returns a string uniquely identifying the foreign key. comment Returns the comment associated with the foreign key object, if any. AUTHOR
Dave Rolsky, <autarch@urth.org> perl v5.8.8 2007-12-23 Alzabo::ForeignKey(3pm)
All times are GMT -4. The time now is 02:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy