Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Once more, in Perl' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Once more, in Perl
Authored by: ngb on Jan 07, '02 01:22:46PM
Here's a perl version I wrote. I use curl to get the IP address from dyndns and save it to a file so I can keep track of when and how often the number changes. I also use a file for the HTML code so it's not hard-coded into the script.
#!/usr/bin/perl

$rootfilesys = "/Volumes/{Your iDisk}/Sites/";
$ipsource = $rootfilesys."myip.html";
$htmlsource = $rootfilesys."myredirect.html";
$htmldest = $rootfilesys."ipindex.html";

// check that the iDisk is mounted
if (-e $rootfilesys) {
#    print "iDisk is mountedn";
} else {
    die "iDisk not mounted: $!n";
}

`curl -s -i -o /Volumes/ngb/Sites/myip.html http://checkip.dyndns.org`;

// extract the IP number from the resulting file
open (IP_SOURCE, $ipsource);
while () {
    ($ipnum) = /(d+.d+.d+.d+$)/;
      if (defined($ipnum)) {
          last;
      } 
}
close (IP_SOURCE);

open (HTML_SOURCE, $htmlsource);
open (HTML_DEST, ">".$htmldest);
while () {
    s/IPNUM/$ipnum/;
    print HTML_DEST $_;
}
close (HTML_DEST);
close (HTML_SOURCE);
I've removed a bunch of error checking code for readability. Mostly checking that the files are opened and closed correctly.

[ Reply to This | # ]