http://www.perlmonks.org?node_id=1006327


in reply to Script to Notify of Public IP Change

Here is another alternative to retrieving your IP address.

#!/usr/bin/perl -w ###################################################################### +## use strict; use LWP::UserAgent; # NOTE: make sure you mimic a browser with the agent name # whatismyip.com specifically returns a 403 error otherwise my $ua = LWP::UserAgent->new(agent=>"Mozilla/5.0"); my $response = $ua->get("http://automation.whatismyip.com/n09230945.as +p"); if ( $response->is_success ) { # this is how I caught the 403 orginal +ly printf "%s\n",$response->decoded_content; } else { printf "Bad Ju-Ju happened:\n\t%s\n",$response->status_line; } #comparison logic from here.
I hate shelling out to an external command since I'd rather not assume that the command is there in the first place. A pure Perl way is more attractive to me.

You can also look at this solution that I came up with for dealing with that issue by querying the administrative interface of my WRT54G router.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re^2: Script to Notify of Public IP Change
by Arkevius (Initiate) on Nov 29, 2012 at 20:18 UTC
    That is indeed a nice bit of code there. Thanks for the share.

    I was also looking at querying the router they have, and actually tried a bit of code, but ran into an access problem. So, I just gave up and went the simpler way. I'll definitely have to read your solution a bit more in full later when I have the time.