#!/usr/bin/perl # seti progress perl script... aka 'prog' # # version 1.0, finished 2004.04.07 # # by Thirteenth Shore Productions # # www.thirteenthshore.com # # general use might be to add an alias to your .tcshrc or the like. # alias monitor "perl scriptdir/iMonitor.pl -v" # specify -v for verbose # if ($ARGV[0] eq "-v") { $verbose = 1; } else { $verbose = 0; } @interfaceTypes = ("en0", "en1"); # mapping port names to services. not fully implemented. # %portNames = { "afpovertcp" => "Apple File Sharing", "netbios-ssn" => "Windows File Sharing", "ssh" => "Secure Shell", "3689" => "iTunes Music Sharing", }; # get IP address # if ($verbose) { print "Testing interfaces...\n"; } foreach (@interfaceTypes) { if ($verbose) { print $_ . "... "; } open(IP, "ipconfig getifaddr $_ |") || die "ERROR: cannot use ipconfig.\n"; chomp($answer = ); close(IP); if ($answer ne "") { if ($verbose) { print "Found IP.\n"; } $machineIP = $answer; last; } # end if } # end foreach if ($machineIP eq "") { die "Machine is not connected.\n"; } if ($verbose) { print "Machine IP address is $machineIP.\n"; } # get host name # open(HOST, "host $machineIP |") || die "ERROR: cannot use host.\n";; chomp($machineName = ); close(HOST); $machineName =~ /(.*) domain name pointer (.*)/; $machineName = $2; if ($machineName eq "") { $machineName = $machineIP; } if ($verbose) { print "Machine host name is $machineName.\n"; } # find netstat info # print "\n"; print "Local Port\t\tRemote Port\t\tStatus\n\n"; print "Resolving...\n"; open(STAT, "netstat -W |") || die "ERROR: cannot use netstat.\n"; while () { if (/$machineName/) { @fields = split(/\s+/, $_); if ($fields[4] ne "*.*") { $fields[3] =~ s/$machineName\.//; $fields[4] =~ s/$machineName\.//; print "$fields[3]\t\t$fields[4]\t\t$fields[5]\n"; } # end if } # end if } # end while close(STAT); exit(0);