https://bugs.koozali.org/show_bug.cgi?id=11771
--- Comment #31 from Brian Read <[email protected]> ---
Here's my code for a new action: "wireguard-check-ip"
#!/usr/bin/perl -w
package esmith;
use strict;
use Errno;
use esmith::ConfigDB;
my $netdb = esmith::ConfigDB->open('/home/e-smith/db/networks') or die("Unable
to open networks db");
#check all that is in the network db, and delete any not in the cidr.
my @wg = $netdb->get_all_by_prop(Wireguard=>"wg0");
foreach my $netwg (@wg) {
my $ip = $netwg->key();
my $Mask = $netwg->prop("Mask");
#print "wireguard-check-ip:$ip\/$Mask";
if (! test_for_private_ip($ip,$Mask)) {
#Log it .....
print "wireguard-check-ip:$ip\/$Mask not CIDR and deleted from Networks
DB";
$netwg->delete();
}
}
sub test_for_private_ip {
use NetAddr::IP;
$_ = shift;
my $mask = shift;
return unless /(\d+\.\d+\.\d+\.\d+)/;
my $iprange = NetAddr::IP->new($1,"$mask");
return unless $iprange;
return ($iprange->first()->is_rfc1918() and
$iprange->last()->is_rfc1918());
}
1
Comments?
--
You are receiving this mail because:
You are the assignee for the bug._______________________________________________
Mail for each SME Contribs bug report
To unsubscribe, e-mail [email protected]
Searchable archive at https://lists.contribs.org/mailman/public/contribteam/