Initial commit
This commit is contained in:
commit
619c202a7d
17
README
Executable file
17
README
Executable file
|
@ -0,0 +1,17 @@
|
|||
phpIPAddress
|
||||
leander@one-button.org
|
||||
|
||||
I wrote this to save the IP address of the client that downloads it.
|
||||
This was mostly done to overcome having a box on on dynamic IP address that I had to access from the outside world.
|
||||
|
||||
It's rather simple, if $save_to_file is set to TRUE the script will save the IP address and hostname to a file. Otherwise it'll just diplsay it in the web browser.
|
||||
By default this file is called ipaddress.txt and is located in the same directory as the PHP script itself.
|
||||
|
||||
The best way to use this is to have the machine who's IP you're trying to keep track of download the script every few minutes.
|
||||
You'll need to place the script itself on a webserver that is accessible (and preferably pretty reliable) to the cleint machine.
|
||||
|
||||
Simply add this to your cleint's crontab:
|
||||
|
||||
*/15 * * * * wget -O - -q -t 1 example.com/phpipaddress/index.php >/dev/null 2>&1
|
||||
|
||||
You can substitute wget for your favorite http client.
|
36
index.php
Executable file
36
index.php
Executable file
|
@ -0,0 +1,36 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>PHP External IP Address Finder</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
// User definable varibales
|
||||
// Set save_to_file = "TRUE" to write the IP address
|
||||
// hostname, and date to a text file
|
||||
// timezone - should be the timezone where the server is located
|
||||
// filename - text file for storing the IP, hostname and date. By default ipaddress.txt
|
||||
|
||||
$save_to_file = "TRUE";
|
||||
$timezone = 'America/New_York';
|
||||
$filename = "ipaddress.txt";
|
||||
|
||||
|
||||
$address = $_SERVER['REMOTE_ADDR'];
|
||||
$hostname = gethostbyaddr($address);
|
||||
date_default_timezone_set($timezone);
|
||||
$dateandtime = date(DATE_RFC822);
|
||||
$writeout = "IP Address: " . $address . "<br>" . "Hostname: " . $hostname . "<br>" . "Last update: " . $dateandtime;
|
||||
echo $writeout;
|
||||
|
||||
if ($save_to_file == "TRUE") {
|
||||
|
||||
$ipFileHandler = fopen($filename, 'w') or die("<br>ERROR CREATING FILE. CHECK DIRECTORY PERMISSIONS<br>");
|
||||
fwrite($ipFileHandler, "IP Address: " . $address . "\n" . "Hostname: " . $hostname . "\n" . "Last update: " . $dateandtime);
|
||||
fclose($ipFileHandler);
|
||||
}
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user