By Marcel.de.Haas on
Hi All,
I want to know if it is possible to resolve the IP addresses in the logs of Drupal. I searched the forums but cannot find any clues. Hope someone can shed some light :).
Note: I'm using 4.7 because of theme compatibility.
Cheers Marcel
Comments
individual IPs could be
individual IPs could be resolved to an owner using something like http://www.ripe.net/whois
Or do you mean something else by "resolve the IP address"?
Google for "Reverse DNS" and
Google for "Reverse DNS" and you'll find many sites that can take an IP address and find the hostname from it.
Hi all, I know this. But I
Hi all,
I know this. But I don't like copy-pasting all the IP addresses in my logs to a webform. I would like Drupal to try to resolve the IP to a FQDN for me.
Cheers Marcel
Looking to do the same thing
I found this after searching for the same thing. I've seen it done in vBulletin, just resolving the IP to a hostname; in phpBB I found a module that resolved an IP and provided a link to search for whois information. That module let you choose a server to query with the IP address.
Resolving the IP address should be pretty easy. PHP has the function gethostbyaddr which would resolve the IP. All you would need to do is find where the details for the log entry is generated. Then replace the IP address text with the resolved IP name. Or you might want both the IP address and hostname.
I don't have the step by step details but I plan on doing mine. Once I do I'll reply with my details.
Okay, I think I figured out
Okay, I think I figured out how to do it, at least on 5.1
There are only a few places in the logs where I would want to resolve the IP addresses. One is the details page for "Recent Log Entries", found by clicking on the message link. The second is the details page for "Recent Hits" and finally the "Top Visitors" page. In my modification I resolved the IP first and included the IP in parens.
In the watchdog.module file you'd need to:
change line 233 from
$watchdog->hostname,to
gethostbyaddr($watchdog->hostname) . " (" . $watchdog->hostname . ")",In the statistics.module file you'd need to:
change line 192 from
$output .= ' <tr><th>'. t('Hostname') .'</th><td>'. check_plain($access->hostname) .'</td></tr>';to
$output .= ' <tr><th>'. t('Hostname') .'</th><td>'. check_plain(gethostbyaddr($access->hostname)) . " (" . check_plain($access->hostname) . ") " .'</td></tr>';and line 327 from
$rows[] = array($account->hits, ($account->uid ? theme('username', $account) : $account->hostname), format_interval(round($account->total / 1000)), $ban_link);to
$rows[] = array($account->hits, ($account->uid ? theme('username', $account) : gethostbyaddr($account->hostname)." (".$account->hostname.")"), format_interval(round($account->total / 1000)), $ban_link);In this case it only resolves the IP when you've clicked on the details or go to "Top Visitors." I could see having an admin option to not resolve the IP addresses. You could do a lot more but for me it's enough, at least for now.
I've just published a simple
I've just published a simple module that does just that. It's for Drupal 7 though: http://drupal.org/project/resolveip
κατασκευή ιστοσελίδων