Skip to content

Instantly share code, notes, and snippets.

@rogerbush8
Created April 20, 2015 22:21
Show Gist options
  • Save rogerbush8/127d048f3e0c3969ce8a to your computer and use it in GitHub Desktop.
Save rogerbush8/127d048f3e0c3969ce8a to your computer and use it in GitHub Desktop.
Output info on active vpn connections (assumes use of pppd)
#!/usr/bin/perl
# Looks at the output of ps to determine how many pppd children are running,
# each of which corresponds to an active connection. Assumes use of pppd
# as the authenticating agent for the vpn.
my $cmd = 'ps auxwww';
open (my $in, "$cmd |") or die "Couldn't execute command '$cmd'";
my $h = {};
my $tty;
my $line_num = 0;
# ps output target line
# root 27028 0.0 0.0 22520 1328 ? S 18:49 0:00 /usr/sbin/pppd passive nodetach 10.1.13.48:10.1.48.6 refuse-pap auth require-chap name l2tpd file /etc/ppp/options.xl2tpd /dev/pts/4
while (my $line = <$in>) {
if ($line =~ /^(\w+)\s+(\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+)\s+(\d+).*.usr.sbin.pppd passive nodetach (.*) refuse-pap.*etc.ppp.options.xl2tpd (.*)$/) {
my $user = $1;
my $pid = $2;
my $ndot1 = $3; # unused
my $ndot2 = $4; # unused
my $ppid = $5;
my $n4 = $6; # unused
my $ips = $7;
my $tty = $8;
print "$user $pid $ppid $ips $tty\n";
}
}
close ($in);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment