#!/usr/bin/perl -w use strict; my(@tcpstatus,@tcpalive,$date,$line); my($ftp,$www,$ssh,$irc); $date = `date +"%l:%M:%S"`; $ftp = 0; $www = 0; $ssh = 0; $irc = 0; @tcpalive = (); ############################ # get current tcp status # ############################ @tcpstatus = `cat /proc/net/tcp`; ############################ # grab only the ones that # # are marked "Active" (01) # # and put them into new # # array # ############################ foreach (@tcpstatus) { while (/\b01\s/) { push(@tcpalive,$_); last; } } ############################ # ugly. I know there has # # got to be a better way # # to get this done. Step # # through new array and # # add how many times each # # service is found # ############################ foreach (@tcpalive) { while (/:0050\s/) { $www++; last; } } foreach (@tcpalive) { while (/:0016\s/) { $ssh++; last; } } foreach (@tcpalive) { while (/:1A0B\s/) { $irc++; last; } } foreach (@tcpalive) { while (/:0015\s/) { $ftp++; last; } } ############################ # print this out to a file # # used for server side # # includes # ############################ open (FILE, "+>/var/www/web/main.txt"); print FILE "There are $www web, $ftp ftp, $ssh ssh, and $irc irc connections to this server as of $date\n"; close FILE;