#!/usr/bin/perl 
# Copywrite: 
# This Work is copywrite Barry Irwin , Moria Research 1999
# All Rights Reserved
#
# Permission is given for derivitive works to be freely distributed provided
# Original Author is acknowledged, and this copywrite remains intact
#
# DISCLAIMER: Your milage may vary. NO WARRANTY provided. USE, Enjoy, but if
# it blows up , or suchlike, badluck. Author Assumes NO responsibility for
# this work

#VERSION=0.2
# outputs current number of connections on a particular port
# Will need editing for linux

#Active Internet connections
#Proto Recv-Q Send-Q Local Address Foreign Address (state)
#tcp 0 0 146.231.29.2.113 205.236.172.181.4102 SYN_RCVD
# ^^^ local port of interest
#future version
#if ( $ARGV[0] eq "" )
#{
# print "Usage: $0 \n";
# exit;
#}

#uptimestuff
$uptime = `uptime`;

$uptime =~ /up (.*?) day/;
$up = int($1);


$sshcount = 0;
$telcount = 0;

foreach $_ (`netstat -n| grep -v "Proto"`) { 	# grab df table
	($proto, $rque, $sque, $local, $remote, $state) = split(/\s+/);
	#edit this number!-------------------->
	if ($proto eq 'tcp') {
		#print "TCP $_";	
		$sshcount++;
		next;
	} elsif ( $proto eq 'unix') {
	#edit this number!------------------------>
		#print "UDP $_";	
		$telcount++; 
		next;
	}
}

print "$sshcount\n";
print "$telcount\n";
print "$up days\n";
