Update:
For this project I ended up using the ip_address() function from Drupal's core to get the ip address. I then created a small table with some restrictions to prevent too much data from being written.
<?php
/**
* Implements hook_init()
*/
function MY_MODULE_init() {
if(drupal_is_front_page() && user_is_anonymous() && ip_address() !== 'our ip address') {
$ip = ip_address();
$ipdate = time();
$insert = db_insert('mytable')->fields(array(
'ip_address' => $ip,
'ip_date' => $ipdate,
))->execute();
}
}
function MY_MODULE_menu() {
$items = array();
$items['view-results'] = array(
'title' => 'View List of IP Addresses',
'page callback' => 'MY_MODULE_fetch_results',
'access callback' => 'user_is_logged_in',
'type' => MENU_CALLBACK,
);
return $items;
}
function MY_MODULE_fetch_results() {
$result = db_query("SELECT ip_address AS IPADDRESS, ip_date
AS IPDATE
FROM mytable
ORDER BY IPDATE DESC");
print "<title>List of IP Addresses</title>";
print "<h3 style='font-family:verdana, arial'>List of IP Addresses and Dates for Anonymous Users Home Page Visits</h3>";
print "<p style='font-family:verdana, arial; font-size:11px'>Hint: use CTRL + F to find</p>";
print "<div style='font-weight:bold; height:18px; background-color:#f5f1ec; font-family:verdana, arial'>
<div style='width:45%; float:left;'>Ip Address</div>
<div style='width:45%; float:left;'>Date of Visit</div>";
foreach($result as $data) {
print "<div style='font-weight:normal; background-color:#efefef; font-family:verdana, arial; height:18px; margin:4px;font-size:11px'>";
print"<div style='width:45%; float:left;'>". $data->IPADDRESS . "</div>";
printf("<div style='width:45%%; float:left; color:#336699;'>%s</div></div><div style='clear:both;'></div>", format_date($data->IPDATE, 'custom', 'j F Y g:i A'));
}
drupal_exit();
}