Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to perl, need a little help

Status
Not open for further replies.

vwyodapink

Technical User
Nov 12, 2009
3
US
I am trying to make a script that will pull my external IP address, then write the IP to a file with the date after it. I seem to be missing something here as it always gives me a result of could not find the IP. Did I not initialize or use my variables properly, or am I not parsing the site properly? Any help or pointers would be appreciated. Thanks in advance

Perl:
#!/usr/bin/perl -w
use strict;
use warnings;
use File::Slurp;
use LWP::Simple;
use Time::localtime;

# Location of file to write to
my $addresses = '/home/blimpton/Pro/logger/addresses.txt';

# Find out what the external IP is
my $ip = get('[URL unfurl="true"]https://automation.whatismyip.com/n09230945.asp');[/URL]
$ip = 'Could find ip address!' if !$ip;

# Current Date
my $month = localtime->mon + 1;
my $day = localtime->mday;
my $year = localtime->year + 1900;
my $current_date = "$month-$day-$year";

# Write to the file 
if ($ip = write_file($addresses, {append => 1}, $ip . ',' . $current_date . "\n"));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top