5 use vars qw($MAC_PROCESS $PS_STR $MATCH_STR $ASIP_PORT_NO $ASIP_PORT $LSOF);
7 # Written for linux; may have to be modified for your brand of Unix.
9 # Support for FreeBSD added by Joe Clarke <marcus@marcuscom.com>.
10 # Support could probably be extended for *BSD, but I do not have Net or
11 # OpenBSD machines to test with. Code has also been cleaned up and made
12 # to compile under strict.
14 # The new lsof call should also be quicker as it does not involve a
17 # Support has also been added for 16 character usernames.
19 $MAC_PROCESS = "afpd";
20 if ( $^O eq "freebsd" ) {
21 $PS_STR = "-awwxouser,pid,ppid,start,command";
22 $MATCH_STR = '(\w+)\s+(\d+)\s+(\d+)\s+([\d\w:]+)';
26 $MATCH_STR = '\s*(\w+)\s+(\d+)\s+(\d+)\s+\d+\s+([\d\w:]+)';
28 $ASIP_PORT = "afpovertcp";
31 # Change to 0 if you don't have lsof
35 if ( $^O eq "freebsd" ) {
36 open( SOCKSTAT, "sockstat -4 | grep $MAC_PROCESS | grep -v grep |" );
39 next if ( $_ !~ /$MAC_PROCESS/ );
40 $_ =~ /\S+\s+\S+\s+(\d+)\s+\d+\s+[\w\d]+\s+[\d\.:]+\s+([\d\.]+)/;
41 my ( $pid, $addr, $host );
44 $host = gethostbyaddr( pack( 'C4', split ( /\./, $addr ) ), AF_INET );
45 ($host) = ( $host =~ /(^[\w\d\-]+)/ );
49 "PID UID Username Name Logintime Mac\n";
52 elsif ( $LSOF == 1 ) {
53 open( LSOF, "lsof -i :$ASIP_PORT |" );
56 next if ( $_ !~ /$ASIP_PORT/ );
57 $_ =~ /\w+\s+(\d+).*->([\w\.-]+).*/;
61 ($host) = ( $host =~ /(^[\w\d\-]+)/ );
65 "PID UID Username Name Logintime Mac\n";
69 print "PID UID Username Name Logintime\n";
72 open( PS, "ps $PS_STR |" ) || die "Unable to open a pipe to ``ps''";
75 next if ( $_ !~ /$MAC_PROCESS/ );
76 my ( $user, $pid, $ppid, $time, $name, $uid, $t );
84 ( $t, $t, $uid, $t, $t, $t, $name, $t, $t ) = getpwnam($user);
85 printf "%-8d %-8d %-16s %-20s %-9s %s\n", $pid, $uid, $user, $name,