I need to get visitors country information using classic asp 3.0, i’m using below code but it returns me XX instead of country name. any suggestions/help on this.
<%
URL = "http://api.hostip.info/country.php?ip=" & Request.ServerVariables("REMOTE_ADDR")
Set conn = Server.CreateObject("MSXML2.ServerXMLHTTP")
conn.open "GET", URL, False, "", ""
conn.send
UserCountry = conn.ResponseText
Response.Write(UserCountry)
%>
i have also setup a page for view which contains the above code.
http://www.datingmaze.co.uk/rac.asp
If i try http://api.hostip.info/country.php?ip=12.215.42.19 it gives me correct output, but if i tried http://api.hostip.info/country.php?ip=119.152.136.247 gives me wrong output i.e. XX although i provided the correct IP address.
thanks in advance.
You can use GeoIP for this.
They have a free COM API which you can use:
http://www.maxmind.com/app/com
http://www.maxmind.com/GeoIP-COM-1.3.zip
Their COM API exposes the following:
The data that you would receive after lookup:
So instead of the using find_by_name, you would use find_by_addr. Which would lookup the country based on an IPv4-address.
This is a better solution since relying on remote 3rd party providers can be risky. Their site might go down, be under heavy load, etc.
You can download the free version of their IP/Country database here:
http://www.maxmind.com/app/geolitecountry