A Wrapper Class For hostip.info’s GeoLocation Service

March 18, 2009 | By

hostip

GeoLocation refers to identifying a real-world geographic location of a computer, device or website visitor. There are a many websites that provide this service, some are free and some are not. A populare and free one is hostip.info. It provides country, country code, country flag, city, latitude and longitude of an IP address.

This wrapper class is a modified version of the one Scott Hanselman posted in Geolocation/Geotargeting (Reverse IP Address Lookup) in ASP.NET MVC made easy. I modified the class to accept an input string containing an IP address or a domain name to get it’s location, instead of returning the current visitor’s. I add the GetCountryFlagURL function that takes an IP address or a domain name and returns the URL of the country’s flag.

Hanselman’s LocationInfo class contained the coordinates of the IP address. But I removed it, because the coordinate element in the XML data is only returned when there are coordinates in the database, and the LINQ statement throws an exception when the element is missing. The class and the sample projects work with ASP.NET and Windows Forms as well as Mono. The source code includes a Windows Forms project and an ASP.NET project to test the class.

 

Listed at Hot Scripts in ASP.NET

 

Download Class

 


 

Download Source Code

 

 

Filed in: ASP.NET, Mono 2.0, WinForms | Tags: ,

Comments (2)

  1. Hello, this was working great for me until a few weeks ago. I think the api or xml response is different now. you should check it.

  2. Thanks Aron, it looks like they did some changes to the XML response. I updated the code here and in the zipped files to reflect the new changes they made.