0

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 ?

6
  • You said you searched. What did you find? You're looking for IP GeoLocation.
    – M.Babcock
    Mar 10, 2012 at 21:30
  • Yes i found, but i have written above i want to it my own. How provide third party websites these information ? I want not to be depended on ipionfodb or such as ! where they get the information ?
    – icaptan
    Mar 10, 2012 at 21:36
  • 1
    The only way to do this without being dependent on a third party is to use HTML5's GeoLocation ability and do it client side. This has limitations in terms of browser support. I guess you could also purchase an IP GeoLocation database and integrate it in your backend.
    – Mark
    Mar 10, 2012 at 21:38
  • If you're looking for a way to create your own geoip database then the best advice you'll get is not to do it. It isn't worth the headaches.
    – M.Babcock
    Mar 10, 2012 at 21:39
  • @MarkS. thanks ! I will look for HTML5, but i'm really want to know how these GeoLocation databases are created ? How they are doing this ?
    – icaptan
    Mar 10, 2012 at 21:42

3 Answers 3

3

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.

2
  • please see my comment above at my question. I want to learn how they (ipinfodb or similar website) gets the data about which location an ip belongs to.
    – icaptan
    Mar 10, 2012 at 21:37
  • 1
    Services like IpInfoDB collect this information from various services. IP addresses in different regions are provided by different authorities. In North America IP addresses are provided by ARIN (American Registry for Internet Numbers). ARIN releases their database publicly and it is searchable on their site, www.arin.net. Enter an IP address in their WHOIS search box and you'll see who owns it. GeoLocation services make use of this information.
    – Mark
    Mar 10, 2012 at 21:41
2

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.

0
0

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 !

Not the answer you're looking for? Browse other questions tagged or ask your own question.