#!/home/product/code/webui-perl/bin/perl

=head1 NAME

get-external-ip - Get the IP of this box as seen from outside

=head1 SYNOPSIS

get-external-ip

=head1 DESCRIPTION

Does as it says on the tin.  Run this script and it hits whatismyip.com and
fetches the IP address as seen from outside.

=cut

use strict;
use Data::Dumper;

print "Determining External IP...\n";

my $ipsite = qw|http://update01.barracudanetworks.com/cgi-bin/update.cgi|;
my $response = qx( /usr/bin/curl $ipsite 2>/dev/null );
my $ext_ip = "";
my $debug = 0;

print Dumper($response) if ($debug);
if ($response) {
	chomp($response);
	if ($response =~ /Rem-Address:\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/i) { 
		$ext_ip = $1; 
	}
	print "External IP: $ext_ip\n";
} else {
	print "Unable to determine external IP: $response\n";
}
