views:

601

answers:

5

How write code in ASP to get website visitors IP address and Country ID ?

Plz help me, Alex

A: 

You need a geolocation service or a similar lookup.

Eg: http://www.ip2location.com/developers.aspx

o.k.w
A: 

Typically solutions like GeoIP are used to locate an IP address down to a geographical location.

monksy
A: 

First you need the IP, this is reported by your server software. Read the REMOTE_ADDR server header with: Request.ServerVariables(REMOTE_ADDR)

For the country, a popular tool is GeoIP, there are some ASP implementations. Google for GeoIP ASP and you will find a solution.

I try like this <%ip_address = Request.ServerVariables("HTTP_X_FORWARDED_FOR") if ip_address = "" then ip_address = Request.ServerVariables("REMOTE_ADDR") end if response.write ip_address%>The result is display like this "::1". This not display the complete IP
Alex
@Alex: Why do you query for `HTTP_X_FORWARDED_FOR`?
o.k.w
The reason we look for the HTTP_X_FORWARDED_FOR value 1st is because of proxy servers and things of that nature as many users are behind one. If that value is not there we just grab the REMOTE_ADDR. Even by doing this there are going to be times when we do not get an IP Address or what we get is not accurate.
Alex
Yea, there is the proxy problem I didn't think about. Alex comment is right.
+1  A: 

first, this has nothing to do with javascript. second, ip address is usually within the request headers, now you tagged this under java and asp where both provides different ways to retrieve the ip address info (with asp is the REMOTE_ADDR variable).

Once you have the IP address you can perform a lookup query in IP2Country table which are available for free on the net.

You simply should download the csv file and add it to your database

start here: http://software77.net/geo-ip/

Tzury Bar Yochay
+3  A: 

MaxMind provides a high-quality database of ip-country mapping.

Marcin
Also using this on my page. It's awesome! +1
Shaharyar