vwyodapink
Technical User
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"));