Created
December 5, 2014 10:27
-
-
Save geoah/5af179e99b9a84dadb32 to your computer and use it in GitHub Desktop.
EdgeOS kill pptp zombie connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# http://community.ubnt.com/t5/EdgeMAX/PPPoE-Server-static-ip-issues/td-p/489341 | |
use strict; | |
use warnings; | |
use Net::Ping; | |
my $sess_dir = "/opt/vyatta/etc/ravpn/sessions"; | |
opendir(SDIR, "$sess_dir"); | |
my @sessions = readdir(SDIR); | |
close(SDIR); | |
my %sess = (); | |
foreach my $s (@sessions) { | |
if ($s =~ /([^@]+)@([^@]+)/) { | |
$sess{$2} = $1; | |
} | |
} | |
my $sessions = 0; | |
my $alive = 0; | |
my $dead = 0; | |
my $p = Net::Ping->new("icmp"); | |
my @lines = `ip addr sh`; | |
foreach my $line (@lines) { | |
if ($line =~ /^\s+inet \d+\.\d+\.\d+\.\d+ peer (\d+\.\d+\.\d+\.\d+)\/32 scope global (pptp\d+)$/) { | |
$sessions++; | |
my $addr = $1; | |
my $intf = $2; | |
my $user = $sess{$intf}; | |
$user = 'unknown' if ! $user; | |
printf("%-20s %-7s %-15s ",$user, $intf, $addr); | |
if ($p->ping($addr)) { | |
$alive++; | |
print "alive\n"; | |
} else { | |
$dead++; | |
print "NOT alive\n"; | |
print "clearing user $user\n"; | |
my $cmd = "sudo /opt/vyatta/bin/sudo-users/vyatta-kick-ravpn.pl $intf interface"; | |
system($cmd); | |
} | |
} | |
} | |
print "\nsessions: $sessions, alive $alive, dead $dead\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment