looking for the next hop
cc
created: 2006-01-23 19:07:37
hi

I have a vpn network with 2 redundant firewalls.
this perl script should look for the next hop and send a mail by unexpected redirect

#!/usr/bin/perl -w

use strict;
use warnings;

my $PingHost = '192.168.23.1';
my $ExpectedRedirect = '192.168.0.10';
my $MailTo = 'postmaster@domain.net';

my $ip = `ip route flush cache`;

open( INPING, "ping -c 10 $PingHost|" ) || die "ping open failed";
while( my $line =  ) {
  next unless( $line =~ /Redirect Host\(New nexthop: (.*)\)/ );
  next if( $1 eq $ExpectedRedirect );

   open( OUTMAIL, "|mail -s 'VPN Unexpected Redirect: $1' $MailTo" ) || die "pipe to mail failed";
   print OUTMAIL scalar localtime();
   print OUTMAIL "\n\n";
   print OUTMAIL "VPN NETWORK\n";
   print OUTMAIL "Received an unexpected redirect to: $1\n";
   close(OUTMAIL) || warn "bad pipe close";
}

close(INPING) || warn "bad pipe close";

how can I change it to delete routing cache,
before the ping command ?

kind regards
cc
Re: looking for the next hop
created: 2006-01-24 00:54:12
Better check the return value of this line:
ip route flush cache
If you are not logged in as root, you may not have access to he "ip" command. (either wrong permissions or wrong path.)
Re^2: looking for the next hop
cc
created: 2006-01-24 17:12:04
no, I run this script from cron as root user
and it seems to work,
but I don't know if it's a good idea to feed the system with backticks.

perlmonks.org content © perlmonks.org and cc, leighsharpe

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03