Get User’s Country Name Using IP Address


How can get the user’s country name using IP address in Classic ASP and Javascript?

http://www.webservicex.net provides web services for get the country name based on ip address.

In ASP using javascript we can achieve the task.

Step1 : Refer the webservice using SOAPClient object

var strUrlForwebservicex = http://www.webservicex.net/geoipservice.asmx?wsdl

var objSoapClient = Server.CreateObject(‘MSSOAP.SoapClient30’)

objSoapClient.ClientProperty(“ServerHTTPRequest”) = true;

objSoapClient.MSSoapInit(strUrlForwebservicex);

Step2 : Get user’s IP address

var strIPAddress = Request.ServerVariables(“REMOTE_ADDR”);

Step3 : Pass the parametes on GetGeoIP webmethod

var strCountryName =objSoapClient.GetGeoIP(strIPAddress);

Complete Script :

<%

var strUrlForwebservicex = “http://www.webservicex.net/geoipservice.asmx?wsdl”
var objSoapClient = Server.CreateObject(‘MSSOAP.SoapClient30’)
objSoapClient.ClientProperty(“ServerHTTPRequest”) = true;
try
  {
objSoapClient.MSSoapInit(strUrlForwebservicex);
objSoapClient.ConnectorProperty(“ConnectTimeout”) = 600000;
var strIPAddress = Request.ServerVariables(“REMOTE_ADDR”);
var strCountryName =objSoapClient.GetGeoIP(strIPAddress);
if (strCountryName == “RESERVED”)
{
   strCountryName = “”;
}
}
catch (e)
{
strCountryName = “”;

Response.Write(“Following error messages occured : ” + e.message)
}

%>

26 thoughts on “Get User’s Country Name Using IP Address

  1. DMW Technologies (P) Limited launcher an API to extract all possible information from any IP. You can sign up for free for the API at http://geoip.dmwtechnologies.com

    We call it IP Intelligence. It is an open source API which can determine country, state/region, city, US area code, metro code, latitude, and longitude information for IP addresses worldwide. You can download the free sample code in PHP5

    GeoIP is a easy to use API to extract all possible information from the IP address. GeoIP API is Technology, Language and Platform independent. This means you can use it in any program, any application or any language.

    Allow me to demonstrate how simple it is to use it:

    Usage:
    http://geoip.dmwtechnologies.com/api.php?apikey=YOUR_API_KEY_HERE&ip=ANY_IP_ADDRESS

    Example:
    http://geoip.dmwtechnologies.com/api.php?apikey=dgsdge734hdfhs644w3yehyw34yy34y&ip=214.25.34.12

    You can get your FREE API KEY in less than 5 minutes. The Free account enables you to extract the country from IP address. One can also extract other vital information for the IP like City, Longitude, Latitude etc by upgrading to the premium account for a small fee .The details of our premium packages are as follows:

    $15 for 50,000 IPs

    $30 for 125,000 IPs

    $50 for 250,000 IPs

    $90 for 500,000 IPs

    $120 for 750,000 IPs

  2. Hi balanagaraj,

    Thanks for the script. I pasted the script in location.asp and replaced the ASP <% sign with the but I am getting the error Server is undefined at line

    var objSoapClient = Server.CreateObject(‘MSSOAP.SoapClient30’)

    Is there anything which I am mising

  3. Appreciating the time and energy you put into your site and detailed information you present. It’s good to come across a blog every once in a while that isn’t the same outdated rehashed material. Wonderful read! I’ve bookmarked your site and I’m including your RSS feeds to my Google account.

  4. Pingback: Getting country name of users using their IP address – PHP – CatchErrors

Leave a reply to larParrava Cancel reply