Hi to all, this is my first script that I post here. Is a simple way to replace the DDNS free services.

Basically it stores the IP (retrieved from the italian site www.chisono.it) in a text file (that must exist) and checks it whenever the crond daemon decides to do.

The script should be executed by cron not often (for me a nice time would be 30 minutes) and requires a MTA installed on the system to work, and also the mailx app.

The logit function is stolen from http://lexington.pm.org/meetings/022001.html

Every comment is appreciated...I know that there's a lot to do to improve it (such add the file existence check and a library for smtp support) but is my quick-and-dirty interpretation of perl....

#!/usr/bin/perl use strict; use LWP::Simple; use Sys::Syslog qw( :DEFAULT setlogsock); my $dir = "/root/script/"; my $emailadd = "your\@email.com"; my $fromadd = "ipwatch\@yourmachine"; chdir $dir; my $current_ip = get('http://www.chisono.it/ip.asp') || logit('err', " +Cannot retrieve the IP address: $!\n"); my ($a1, $a2, $a3, $a4) = split /\./, $current_ip; open FILE, "myip.txt" or logit('err', "Cannot open the file: $!\n"); my $readip = <FILE>; my ($b1, $b2, $b3, $b4) = split /\./, $readip; if ($readip eq $current_ip) { logit('info', "Address not changed\n"); } else { logit('info', "Address changed: old IP: $readip ; New IP: $curr +ent_ip\n"); getstore('http://www.chisono.it/ip.asp', 'myip.txt'); system("mailx -s \"IP changed!\" -a \"From: IPWatch <$fromadd>\ +" $emailadd < myip.txt") || logit('err', "Cannot send the email!\n"); } sub logit { my ($priority, $msg) = @_; return 0 unless ($priority =~ /info|err|debug/); setlogsock('unix'); openlog($0, 'pid,cons', 'user'); syslog($priority, $msg); closelog(); return 1; }

In reply to Send your IP by fixed

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.