#!/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";