#!/usr/bin/perl -w ###################################################################### # afraid.pl for freedns.afraid.org # FreeDNS_Updater/1.2 [Aug 12 2004] # Author: Aleksandr Melentiev # E-mail: tzapper@users.sourceforge.net # Description: # This script runs in the background checking for IP changes, if a # change has been detected, it automatically updates the Dynamic DNS # Tested on FreeBSD 5.1 ###################################################################### require 5.004; use LWP; use POSIX qw(setsid); our $VERSION = 1.2; ########################### # Configuration variables # ########################### ### Update URLs, multiple URLs are accepted @url= qw(http://freedns.afraid.org/dynamic/update.php?string1 http://freedns.afraid.org/dynamic/update.php?string2); ### Interface to grab the current IP from, e.g. fxp0, dc0, tun0 $iface = "tun0"; ### E-mail address for error notifications $email = 'your@email.address'; ##################### # End Configuration # ##################### $SIG{CHLD} = 'IGNORE'; $SIG{QUIT} = 'sigQuit'; $SIG{TERM} = 'sigQuit'; $SIG{ABRT} = 'sigQuit'; $SIG{INT} = 'sigQuit'; &daemonize; $sysCmd = "ifconfig $iface | awk '/inet/{print \$2;}'"; $ip = qx{$sysCmd}; $agent = "FreeDNS_Updater/$VERSION"; $browser = LWP::UserAgent->new(); $browser->agent("$agent"); main(); sub main { update(); while (1) { $currentip = qx{$sysCmd}; if ("$ip" ne "$currentip") { update(); $ip = $currentip; } sleep 10; } } sub update { foreach $updlink (@url) { $updurl = $browser->request(HTTP::Request->new(GET => $updlink +)); if ($updurl->is_error) { open MAIL,"|mail $email"; print MAIL "$agent: $0 [Couldnt update $updlink]\n"; close MAIL; return 0; } } } sub daemonize { defined($pid = fork) or die "Can't fork: $!"; exit if $pid; setsid or die "Can't start a new session: $!"; umask 0; $PID = "/var/run/afraid.pid"; open PID,">$PID" or die ( $! ); print PID $$; close PID; } sub sigQuit { unlink $PID; exit; } 1; __END__

In reply to FreeDNS_Updater by TZapper

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.