Click here to Skip to main content
15,867,756 members
Articles / Programming Languages / ASP
Article

GeoIP - Where are your internet visitors coming from?

Rate me:
Please Sign up or sign in to vote.
4.82/5 (17 votes)
31 Aug 20031 min read 276.8K   3.2K   75   33
Where are your internet visitors coming from?

Introduction

With GeoIP you can detect where your visitors are coming from. You can use this information to deliver personalized information (see image below), reducing credit card fraud, analyzing web server logs (I use it for SNIFF), target banner ads, .... (see Solutions at MaxMind - http://www.maxmind.com/)


Click on the image for a test

Note

If you can install a component on your web server, you should download the GeoIP component from MaxMind . I wrote GeoIP.asp since my provider doesn't allow me to install components.

Prerequisite

(Updated 1.sep.03, new urls) You need the GeoIP database - http://www.maxmind.com/app/standard, and you need ADO 2.5 or later since GeoIP.asp uses the ADO Stream object to read the GeoIP database.

Installation

  1. Download the GeoIP.dat database from MaxMind
    http://www.maxmind.com/app/standard
  2. Put GeoIP.asp, example.asp and GeoIP.dat in a catalog on your web server.
  3. Test the installation by accessing the example.asp page
    http://yourserver/path/example.asp

Methods and Properties

GeoIP.asp exposes these public methods and properties

Properties

  • GeoIPDataBase - Sets the path and filename to GeoIP.dat
  • ErrNum - Returns the error number (if <> 0, there's an error)

Methods

  • lookupCountryName - Find an IP's country name
    • example: strCountryName = oGeoIP.lookupCountryName(strIP)
  • lookupCountryCode - Find an IP's country code
    • example: strCountryCode = oGeoIP.lookupCountryCode(strIP)

Using the code

It's rather simple to use this code:

VBScript
<!--#include file="GeoIP.asp"-->
<%
Dim oGeoIP,strErrMsg
Dim strIP,strCountryName,strCountryCode

Set oGeoIP = New CountryLookup
oGeoIP.GeoIPDataBase = Server.MapPath("GeoIP.dat")
If oGeoIP.ErrNum(strErrMsg) <> 0 Then
	Response.Write(strErrMsg)
Else
	strIP = request.ServerVariables("REMOTE_ADDR")
	strCountryName = oGeoIP.lookupCountryName(strIP)
	strCountryCode = oGeoIP.lookupCountryCode(strIP)
End If
Set oGeoIP = Nothing
%>

Have fun coding, Per

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionCities? Pin
zorlus22-Nov-09 3:19
zorlus22-Nov-09 3:19 
QuestionHow to make custom geo-Ip solution... Pin
Oleksandr Kucherenko15-Sep-08 6:28
Oleksandr Kucherenko15-Sep-08 6:28 
GeneralOne more... Pin
Vasudevan Deepak Kumar7-Mar-06 22:48
Vasudevan Deepak Kumar7-Mar-06 22:48 
GeneralEuropean Union Pin
Sehl11-Jan-06 5:04
Sehl11-Jan-06 5:04 
GeneralTHANK U ! Pin
nt110-Apr-05 10:34
nt110-Apr-05 10:34 
one of the best, most practical articles i have seen.
GeneralSvensk flagga ist&#228;llet f&#246;r Dansk Pin
micke122-Aug-04 13:46
micke122-Aug-04 13:46 
GeneralRe: Svensk flagga ist&#228;llet f&#246;r Dansk Pin
Per S22-Aug-04 15:11
Per S22-Aug-04 15:11 
GeneralRe: Svensk flagga ist&#228;llet f&#246;r Dansk Pin
micke122-Aug-04 15:35
micke122-Aug-04 15:35 
GeneralExcellent Pin
Anonymous10-Aug-04 13:48
Anonymous10-Aug-04 13:48 
GeneralI am not in the USA Pin
Anonymous12-May-04 0:32
Anonymous12-May-04 0:32 
GeneralRe: I am not in the USA Pin
Landarzar6-Aug-06 5:14
Landarzar6-Aug-06 5:14 
GeneralError Pin
Member 222248422-Feb-04 22:50
Member 222248422-Feb-04 22:50 
GeneralRe: Error Pin
Per Søderlind22-Feb-04 23:25
sussPer Søderlind22-Feb-04 23:25 
Generalerror Pin
Zaboss28-Dec-03 23:08
Zaboss28-Dec-03 23:08 
GeneralRe: error Pin
Per Søderlind28-Dec-03 23:31
sussPer Søderlind28-Dec-03 23:31 
GeneralRe: error Pin
Zaboss28-Dec-03 23:43
Zaboss28-Dec-03 23:43 
GeneralFind users' city, region and country if ...... Pin
garyyuan9-Sep-03 9:43
garyyuan9-Sep-03 9:43 
GeneralRe: Find users' city, region and country if ...... Pin
Per S9-Sep-03 10:16
Per S9-Sep-03 10:16 
GeneralRe: Find users' city, region and country if ...... Pin
garyyuan9-Sep-03 10:27
garyyuan9-Sep-03 10:27 
GeneralRe: Find users' city, region and country if ...... Pin
Per S9-Sep-03 10:36
Per S9-Sep-03 10:36 
GeneralRe: Find users' city, region and country if ...... Pin
Lomax_zzz1-Jan-05 16:17
sussLomax_zzz1-Jan-05 16:17 
GeneralNice! Like it Pin
1-Sep-03 12:37
suss1-Sep-03 12:37 
GeneralAwesome Pin
Larry Antram12-Jan-03 16:34
Larry Antram12-Jan-03 16:34 
GeneralExcelent Pin
Julio Rios10-Dec-02 7:29
Julio Rios10-Dec-02 7:29 
GeneralRe: Excelent Pin
Per S10-Dec-02 8:37
Per S10-Dec-02 8:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.