icaptan
icaptan

Reputation: 1535

IP and Location information

I've searched about ip & location for my website. I want to know where my visitor have entered the website. According to his location i will make some recordings, show the website with a different theme and so on.

I'm using Asp.Net, I would not use any providers or tools. I want to do it my own. How can I do it ? What shall I search ?

Upvotes: 0

Views: 4608

Answers (3)

Raphaël Roux
Raphaël Roux

Reputation: 356

You have to use a third party service to fetch geo information about your user. I personally use https://api.iplocation.net/ that is free and without registration. It fits my need as I just need to know the country iso code. You just have to make an http request to an api endpoint to get a json response. Happy coding !

Upvotes: 0

Ronald Weidner
Ronald Weidner

Reputation: 690

The concept you are talking about is called Geo Location. The gist of it is there are databases that map ip addresses to ISP and ISP to physical locations. Here is the google search I used.

geo locate ip address

This page was particuarly interesting because it offered a good explication and some sources for free data.

http://www.iplocation.net/

Good Luck.

Upvotes: 2

Mark
Mark

Reputation: 21626

You'll need to use a third party service or tool to gather GeoLocation. I suggest trying out the IPInfoDB, http://www.ipinfodb.com , which is a free GeoLocation service. Once you sign up for an API key you can consume the service in C# as follows:

 public static GeoLocation HostIpToPlaceName(string ip)
    {
        string url = "http://api.ipinfodb.com/v2/ip_query.php?key={enterAPIKeyHere}&ip={0}&timezone=false";
        url = String.Format(url, ip);

        var result = XDocument.Load(url);

        var location = (from x in result.Descendants("Response")
                        select new GeoLocation
                        {
                            City = (string)x.Element("City"),
                            Region = (string)x.Element("RegionName"),
                            CountryId = (string)x.Element("CountryName")
                        }).First();

        return location;
    }

There are many services that provide GeoLocation but IPInfoDB is free and has worked well for me.

You can also gather this information on the client side using HTML5 as demonstrated at http://html5demos.com/geo . Of course if you want to use this information in your code you would somehow have to pass it to the backend.

Upvotes: 3

Related Questions