[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cobalt-users] Great, VPN WHO Script



I don't know if people are interested in this script but I sure was and now
I have found it.  I wanted a script that would show me the PPTP VPN
connections to our server.  Now I can see this using the following script by
Jason:

#!/usr/bin/perl
# By Jason Collins-Webb (jason@xxxxxxxxxxxx)
# usage: vpnwho
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Your copy is available at: http://www.gnu.org/licenses/gpl.html
#

$TDateM = substr(`/bin/date +"%b"`, 0, -1);
$TDateD = substr(`/bin/date +"%e"`, 0, -1);
$whoson = `/bin/ps -eo pid,bsdstart,cmd|/bin/grep "pptpd \\["`;
if ($whoson ne "") {
@logons = split(/\n/, $whoson);
foreach $l (@logons) {
if ($l =~ /(\d+)\s+(\d+:\d+).*\[(\d+\.\d+\.\d+\.\d+)\]/) {
$PID = $1+1;
$IP = $3;
$STIME = $2;
open MESSAGES, "</var/log/messages";
while(<MESSAGES>){
if ($_ =~ /.*\spppd\[$PID\]:\s+MSCHAP-v2\s.*\s(.+\\)*(.+)$/i) {
$User = lc($2);
}
}
close MESSAGES;
print "Current VPN connection from $User ($IP), started at $STIME\n";
}
}
} else {
print "There are no current VPN connections.\n";
}

Just save it to your /usr/bin as whovpn and chmod the file 755 and then just
run it by typing whovpn and enter and it will tell you the user connected to
the VPN, the source IP, and when it connected.

Thanks a lot to the author of such a nice script.

Santiago.
______________________________
Santiago Montalvan
Information Systems Consultant
www.montalvanware.com