To use Scheduled HTTP Get to display your IP address to others on the
Internet, you will have to do some minimal programming. The code below is a
simple example of a PHP page that logs and displays your IP address. The code
examples can be found in the programs folder.
myip.php
<?
// Minimal IP save/display page. Uses ScheduledHTTPGET.exe
// By Jim Chevalier, jimbug.org
// Edit the next three lines as needed. No other lines need to be changed.
$pass = "put_a_unique_password_here"; //
A password passed so we know it's our IP. Same as ScheduledHTTPGET.exe is
sending.
$datadir = "/home/username/writable/"; //
Path to a writable directory. Example: "/home/username/writable/"
$datafile = $datadir . "myip.txt"; //
Writable text file to store our IP address. Example: "myip.txt"
// If password is OK, save my IP.
// Also could check $HTTP_USER_AGENT to only respond to ScheduledHTTPGET.exe,
and not to a browser
if ($pass == $QUERY_STRING)
{
// Open data file
$fhandle = @fopen("$datafile", "w");
// get data
$theDate = date("h:i
a F j, Y");
$message = "$theDate\n";
$message .= "$REMOTE_ADDR\n";
$message .= gethostbyaddr($REMOTE_ADDR) . "\n";
$message .= "User Agent = $HTTP_USER_AGENT\n";
$message .= "Referer = $HTTP_REFERER\n";
// Write data to file
@fputs($fhandle, "$message\n");
// Close file, exit
@fclose($fhandle);
print("$REMOTE_ADDR");
exit;
}
if (file_exists($datafile))
{
$stuff = @file($datafile);
$date = $stuff[0];
$ip = chop($stuff[1]);
}
else
{
$ip = "<p>Error: File not found!<br>\n\"$datafile\"</p>";
}
?>
<html>
<head>
<meta HTTP-EQUIV="refresh" CONTENT="60;URL=<? print($PHP_SELF) ?>">
<title>My Current IP Address: <? print($ip) ?></title>
</head>
<body bgcolor="#003366" text="#009999">
<h3>My Current IP address is: <? print($ip) ?></h3>
</body>
</html>
The above PHP page will save your IP address to a text file on the server if
it is passed the correct password. You will first have to edit the lines (6-8).
For example, the URL to this page is: http://www.mydomain.org/home/myip.php.
And the password is: peanutbuttersandwich. Then put in Scheduled HTTP
Get's URL field: http://www.mydomain.org/home/myip.php?peanutbuttersandwich.
This full URL could also be entered in browser or with the perl
script below. Now, when someone goes to http://www.mydomain.org/home/myip.php,
they will see your IP address. Make
sure you have a good firewall! [ top ]
redir.php
<?
// Minimal IP save/redirect page. Uses ScheduledHTTPGET.exe
// When people browse to this page, they are automatically redirected to
your home web server.
// By Jim Chevalier, jimbug.org
// Edit the next three lines as needed. No other lines need to be changed.
$pass = "put_a_unique_password_here"; //
A password passed so we know it's our IP. Same as ScheduledHTTPGET.exe is
sending.
$datadir = "/home/username/writable/"; //
Path to a writable directory. You could use "/tmp/" on unix server
$datafile = $datadir . "myip.txt"; //
The name of a text file to store our IP address.
// If password is OK, save my IP.
// Also could check $HTTP_USER_AGENT to only respond to ScheduledHTTPGET.exe,
and not to a browser
if ($pass == $QUERY_STRING)
{
// Open data file
$fhandle = @fopen("$datafile", "w");
// get data
$theDate = date("h:i
a F j, Y");
$message = "$theDate\n";
$message .= "$REMOTE_ADDR\n";
$message .= gethostbyaddr($REMOTE_ADDR) . "\n";
$message .= "User Agent = $HTTP_USER_AGENT\n";
$message .= "Referer = $HTTP_REFERER\n";
// Write data to file
@fputs($fhandle, "$message\n");
// Close file, exit
@fclose($fhandle);
print("$REMOTE_ADDR");
exit;
}
// Browsers enter here
elseif (file_exists($datafile))
{
$stuff = @file($datafile);
$date = $stuff[0];
$ip = chop($stuff[1]);
header("Location: http://$ip/");
}
else
print("<p>Error: File not found!<br>\n\"$datafile\"</p>");
?>
The above PHP page is a variant of the previous web page and will automatically
redirect viewers to your home web server. You will first have to edit the lines
(7-9). For example, the URL to this page is: http://www.mydomain.org/home/redir.php.
And the password is: peanutbuttersandwich. Then put in Scheduled HTTP
Get's URL field: http://www.mydomain.org/home/redir.php?peanutbuttersandwich.
This full URL could also be entered in browser or with the perl
script below. Now, when someone goes to http://www.mydomain.org/home/redir.php,
they will automatically be redirected to your home web server. Make
sure you have a good firewall! [ top ]
getmyip.pl
#!/usr/bin/perl
use LWP::Simple;
$doc = get
'http://www.mydomain.org/home/myip.php?password';
#print $doc;
exit;
The above perl script can be used if you have a home web server to log your IP
address. You could run this on boot and set up a cron job to run this script every
hour or so. Edit the 3rd line as needed to point to the PHP page.
Remember, all the code examples can be found in the programs
folder. [ top ]