8.10. Tracking and Blocking Visitors Based on Their IP Numbers

Problem

You need to determine the geographic location or Internet service provider of a visitor, possibly because you suspect he is attempting to abuse or defraud your site.

Solution

Make a note of the visitor's IP number, and then submit the IP number as a query to the American Registry for Internet Numbers (ARIN) whois search form at http://www.arin.net/whois.

Discussion

IP numbers are unique identifiers for every machine connected to the Internet. They take the form of a dotted quad—four numbers between 0 and 255 separated by periods. For example, my PC's IP number is 70.113.31.107.

You should be able to get the IP number of a visitor from your web server access log or from your online store transaction records. If you receive an email from a visitor and can view the message header information with your email client, you might be able to get an IP number that way, too.

Search results from the ARIN database should supply you with the name, address, and phone number of the owner of the IP number (typically, the IP address belongs to an Internet service provider, not the end user). If the number is not in the ARIN registry, the results page might refer you to another regional registry where you can try another search. With this information, you can contact the ISP and report the suspicious activity.

You also might want to deny the visitor access to your site by blocking his IP number. Adding a few lines to an .htaccess file ...

Get Web Site Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.