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

TMTOWTDI | 10 comments | Create New Account
Click here to return to the 'TMTOWTDI' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Authored by: frogger on Nov 16, '01 01:22:21PM

Here is a script that I use to check my IP, generate a small html page, and ftp it to an external web server. The advantage of this way is not having to have your iDisk mounted all the time. Unfortunately, you cannot access your iDisk via ftp, so this will only work if you have webspace somewhere else.

The ftp script (mentioned in the script below) is just a small text file that feeds instructions to the ftp program. (Mine has only 2 lines: cd public_html; put ipaddress.html -- YMMV) The ftp script is in my home directory.

Put the script listed below in your bin directory and make it executable. When making a crontab to run the script, BE SURE TO PROVIDE THE PATH TO THE SCRIPT. e.g. /Users/yourname/bin/ipscript

When I first set this up, it wouldn't execute without the full path, even though the bin dir is in my path. Oh well.

One last note, I use grep to find the line with the IP address, and instead of XXX I have 3 numbers that never change when I am issued my IP address (the first three).

#Executable script

ip=`curl -s | grep XXX | awk '{print $4}'`

echo "<html><head><title>Current IP Check</title></head>
<body bgcolor=white text=black>
Current IP Address: $ip<br>
<a href="http://$ip">Clickable</a><br><br><b>" > $page
date >> $page
echo '</b><br><br><PRE>' >> $page
who | awk '{print $1}' >> $page
echo '</PRE><br><br><a href=><img src="/images/afunpic.gif"></a>' >> $page
echo '</body></html>' >> $page
ftp < ftpscript

[ Reply to This | # ]
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.

$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`;

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

open (HTML_SOURCE, $htmlsource);
open (HTML_DEST, ">".$htmldest);
while () {
    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 | # ]
egrep refinement for TMTOWTDI
Authored by: sophistry on Feb 04, '03 05:17:52PM

curl -s | egrep '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | cut -d" " -f4

[ Reply to This | # ]