|
|
Once more, in Perl
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.
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.13 seconds |
|