Friday, 28 November 2008

Can I has IP?

A quicky Perl utility that interrogates the DNS-O-Matic IP page which returns your public IP address.#!/usr/bin/perl

# cihip (Can I Has IP?)

use strict;
use warnings;
use LWP::Simple;

my ( $address, $error ) = get_address();

if ( $error ) {

print ( "$error\n" );
die "cihip failed: $error\n";

}

sub get_address {

$address = get( "http://myip.dnsomatic.com/" );

if ($address) {

print "$address\n";

} else {

$address = 0;
$error = "IP address query failed:\n";

}

return ( $address, $error );

}

No comments: