Build Your Own IP Grabber in PHP

Method #1

<?php
 
//IP Grabber
 
//Variables
 
$protocol = $_SERVER['SERVER_PROTOCOL'];
$ip = $_SERVER['REMOTE_ADDR'];
$port = $_SERVER['REMOTE_PORT'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$ref = $_SERVER['HTTP_REFERER'];
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
 
//Print IP, Hostname, Port Number, User Agent and Referer To Log.TXT
 
$fh = fopen('log.txt', 'a');
fwrite($fh, 'IP Address: '."".$ip ."\n");
fwrite($fh, 'Hostname: '."".$hostname ."\n");
fwrite($fh, 'Port Number: '."".$port ."\n");
fwrite($fh, 'User Agent: '."".$agent ."\n");
fwrite($fh, 'HTTP Referer: '."".$ref ."\n\n");
fclose($fh);
?>

Method #2

How to Steal IP Address via Image

Create a file name functions.php

<?php function getBrowser()
{
    if (isset($_SERVER['HTTP_USER_AGENT']) && !empty($_SERVER['HTTP_USER_AGENT']))
    {
        return $_SERVER['HTTP_USER_AGENT'];
    }
    else
    {
        return "Unknown User-Agent";
    }
}
function getIP()
{

    if (function_exists('apache_request_headers'))
    {

        $headers = apache_request_headers();

    }
    else
    {

        $headers = $_SERVER;

    }

    if (array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER$

    return $headers['X-Forwarded-For'];

}
elseif (array_key_exists('HTTP_X_FORWARDED_FOR', $headers) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VAL$

return $headers['HTTP_X_FORWARDED_FOR'];

}
else
{

    return filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);

}

}

function getReferer()
{
    if (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['REMOTE_ADDR']))
    {
        return $_SERVER['REMOTE_ADDR'];
    }
    else
    {
        return "Unknown Referer";
    }
} ?>

Create another file named log.php

<?php include 'functions.php';
$browser = getBrowser();

$date     = date('m/j/y g:i A');

$ip       = getIP();

$referer = getReferer();

$log     = fopen('logs.txt', 'a');
fwrite($log, '[' . $date . '] ' . $browser . '|' . $ip . '|' . $referer . "rn");
fclose($log);
echo '<img src="birdy.jpg">'; ?>

Create a file named .htaccess

Options All -Indexes

RewriteEngine on RewriteRule ^bird.jpg$ log.php

<Files *.txt> Order Deny,Allow Deny from all </Files>

<files ~ "^.*.([Hh][Tt][Aa])"> order allow,deny deny from all satisfy all </files>
  • Create an empty text file, and name it logs.txt

  • Create an empty text file, and rename it to bird.jpg

  • Upload a JPG file as birdy.jpg

Anytime someone goes to bird.jpg on your server, it will load log.php, but the URL will still show as bird.jpg