codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:



Home » ASP » Article

Find Visitor Geographical location from IP address using ASP

Article by: Per Soderlind (2/26/2003)
Bookmark us now! Add to Favourites
Email a friend!Tell a friend
Sponsored by: FindMyHosting - Web Hosting Search
Summary: Where are your internet visitors coming from? Using simple ASP and the free GEOIP Database from Maxmind its quite easy to find out
Viewed: 72374 times Rating (14 votes): 
 3.7 out of 5
 Rate this Article  Read Comments  Post Comments

Find Visitor Geographical location from IP address using ASP



Download GeoIP files - 6 Kb
Online Demo

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

You need the GeoIP database - http://www.maxmind.com/app/free, and you need ADO 2.5 or later since GeoIP.asp uses the ADO Stream object to read the GeoIP database.

Installation

Download the GeoIP.dat database from MaxMind http://www.maxmind.com/app/free Put GeoIP.asp, example.asp and GeoIP.dat in a catalog on your web server. 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:

Select All Code







CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'Find Visitor Geographical location from IP address using ASP'
Posted by :  Archive Import (pg) at 23:41 on Wednesday, April 23, 2003
need geoip.dat
tried at http://www.maxmind.com/download/geoip/database/ but the file therre is geoip.dat.gz

upon clicking it opens some viewer (VRML, I think) but nothing loads.

So, downloaded the file geoip.dat.gz
Upon trying to access locally, again nothing loads but this time there is an error, "Compilation error: Unrecoginsed header string"

Can someone help?
Posted by :  Archive Import (pg) at 23:45 on Wednesday, April 23, 2003
One more question:

Is there a free php solution for resolving IP to Country that I can use on my site?
Posted by :  Archive Import (maty ponpon) at 23:22 on Monday, April 28, 2003
i would like to know how to find a user's IP on a forum (what ever forum it is...)Thanks
Posted by :  Archive Import (Your Guru) at 15:00 on Sunday, June 01, 2003
Nothing special - it only guesses the country I am from. Anything more specific???
Posted by :  Archive Import (george) at 10:54 on Friday, June 13, 2003
Can someone help me please! How does one locate the state location according to IP address. Any info would be welcome :)
Posted by :  Archive Import (Khalid ) at 07:07 on Monday, July 07, 2003
Sure!!!
I just got the answer once I read your question.

Actually I came here through the following web site"
http://soderlind.no/s/geoip/

Once I read your question, I just knew that the guy who used the same function had already downloaded the file, so

I jsut typed
http://soderlind.no/s/geoip/GeoIP.dat

and got the file you need. :)

GL
Posted by :  Archive Import (swat) at 11:53 on Wednesday, July 23, 2003
The data was WORNG
Posted by :  Archive Import (James Laugesen) at 20:01 on Wednesday, July 23, 2003
It's impossible to accurately resolve location from an IP address because the IP is allocated to users by their ISP, which could be located anywhere and have purchased the IP anyway.
A Danish ISP who has a POP in Sydney, Australia can allocate Danish IP's to users in Sydney.

It's sort of fun.
But definatly not a good idea for validating credit card use.
Posted by :  Archive Import (Amol B Thorat) at 13:34 on Thursday, August 07, 2003
Dear Sir/Madam
I want to knw the location of the following ip
202.21.44.137
Kindly help me on this

thanks and regards
Amol Thorat
Posted by :  Archive Import (nattudurai) at 14:22 on Thursday, August 07, 2003
dear Sir/Madam

i want to know about how to administrator give the permission for
user can see the perticular web page..

i'm waiting for u'r kind reply..
thaking u sir..
Posted by :  Archive Import (Anil) at 09:23 on Sunday, August 17, 2003
Dear Sir/Madam,

I want to know the location (exact address) of the following IP Address

202.52.196.216

Hoping that it's posible to you.

Is it possible to locate the address of actual user through ip address?

pls help me.

eagerly waiting for your reply.

thanking u
anil

Posted by :  Archive Import (anita) at 22:22 on Monday, August 18, 2003
i want to detect IP address by known location. how do i do?
Posted by :  Archive Import (Yo) at 18:46 on Sunday, August 24, 2003
I don't live in Norway unless you spell Norway... C,A,N,A,D,A eh!
Posted by :  Archive Import (Mikey D) at 01:07 on Tuesday, September 02, 2003
Hi.

I was wondering how to find a location for an ip address. I tried a couple on the internet using my own ip address and it was giving me a location of virginia when i live in pa. Can someone please help?
Posted by :  Archive Import (Travis) at 02:32 on Monday, September 15, 2003
If possible, please give info on 213.158.72.1
Posted by :  fadly at 08:55 on Monday, October 20, 2003
hi, i was download it. but how know about them have ISP?? like this
IP Address Country (Short) Country (Full) Flag Region City ISP
202.155.59.222 ID INDONESIA - - HOST BATAM MATSUSHITA BATTERY
pls help me


<Added>

hi, i was download it. but how know about them have ISP(in the underlined text and bold?? like this
IP Address Country (Short) Country (Full) Flag Region City ISP
202.155.59.222 ID INDONESIA - - HOST BATAM MATSUSHITA BATTERY
pls help me
Posted by :  kunlasethi at 06:15 on Monday, April 05, 2004

the package on longer contain GeoIp.asp and example in the g file
can anyone mail it to me
kunals_libra@yahoo.com?
Posted by :  Priya_India at 07:12 on Thursday, May 19, 2005
The file found nowhere. Simple it takes us to pages and pages like a treasure hunt.
Posted by :  subcom at 21:41 on Monday, September 10, 2007
I wrote an article about how to find country and city by IP address.
I hope it can be used for everyone

http://www.treaple.com/ArticlesDetails.aspx?id=64

Cheers,


<Added>

I just wrote an article about how to find country and city by IP address.
I hope it can be used for everyone
http://www.treaple.com/bbs/viewthread.php?tid=17&extra=page%3D1
Cheers.


To post comments you need to become a member. If you are already a member, please log in .

 



RELATED ARTICLES
ASP Format Date and Time Script
by Jeff Anderson
An ASP script showing the variety of date and time formats possible using the FormatDateTime Function.
ASP FilesystemObject
by Jeff Anderson
An introduction to the Filesystemobject
Email validation using Regular Expression
by Jeff Anderson
Using regular expression syntax is an exellent way to thoroughly validate an email. It's possible in ASP.
Creating a Dynamic Reports using ASP and Excel
by Jeff Anderson
A simple way to generate Excel reports from a database using Excel.
Create an ASP SQL Stored Procedure
by Jeff Anderson
A beginners guide to setting up a stored procedure in SQL server and calling it from an ASP page.
Creating an SQL Trigger
by Jeff Anderson
A beginners guide to creating a Trigger in SQL Server
ASP Shopping Cart
by CodeToad Plus!
Complete source code and demo database(Access, though SQL compatible) to an ASP database driven e-commerce shopping basket, taking the user through from product selection to checkout. Available to CodeToad Plus! Members
Concatenate strings in sql
by Jeff Anderson
A brief introduction to concatenating strings in an sql query (using SQL server or access databases).
ASP OpenTextFile
by Jeff Anderson
An introduction to the OpenTextFile Method of the FileSystemObject
The asp:checkbox and asp:checkboxlist control
by David Sussman, et al
Checkboxes are similar to radio buttons, and in HTML, they were used to allow multiple choices from a group of buttons.








Recent Forum Threads
• hidden div block when displayed, displays at an offset of 200px only in IE 6..
• help - sketch
• Re: Perl Script - File Handling.
• Open a file from website
• Re: to open 5 terminals from one and also execute different commands on each terminal
• read a selected multiple line, those should match some of the values read in the files..
• Help me please
• Empty the contents of a file.
• Month Start, End dates


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008