forked from tyhoff/findUser-Lawson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSHSearch.pl
executable file
·75 lines (59 loc) · 1.5 KB
/
SSHSearch.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl
# Purdue Computer Science lab computer user search.
# finds any computers a user is logged into.
# Credit goes to Caleb for all the code that I
# dissected, including this comment
# Credit goes to Eric Templin for list of Lawson
# Computers
my $in;
my $username;
my $first;
my $last;
my $username = $ARGV[0];
my $currentComputer;
my @localComputers = ();
my @remoteComputers = ();
while($in = <STDIN>) {
# remember current computer name
if ($in =~ /@([a-z0-9]*-?[a-z0-9]*)/) {
$currentComputer = $1;
# user found
} else {
my $date;
my $hostname;
# get date of login
if ($in =~ m/(\w+)(\s+)(\d+)(\s+)(\d+):(\d+)/ ) {
$date = "$1 $3 $5:$6";
}
# logged in locally
if ($in =~ m/($username)(\s+)tty/) {
$str = $currentComputer . " since " . $date;
push(@localComputers, $str);
# logged in remotely
} elsif ($in =~ m/($username)(\s+)pts/) {
if ($in =~ /\(([^\s"]+)\)/) {
$hostname = $1;
}
$str = $currentComputer . " from [ " . $hostname . " ] since " . $date;
push(@remoteComputers, $str);
}
}
}
print "\nLocal connections for $username: \n==============================================\n";
if (@localComputers) {
foreach (@localComputers) {
print "$_ \n";
}
print "\n";
} else {
print "No local connections\n\n";
}
print "Remote connections for $username: \n==============================================\n";
if (@remoteComputers) {
foreach (@remoteComputers) {
print "$_\n";
}
print "\n";
} else {
print "No remote connections\n\n";
}