Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect/estimate country of a http-request in ASP.NET

Tags:

c#

http

asp.net

I'm looking for ways to detect/estimate the country from which a http-request is coming in ASP.NET.
I know there are some solutions with services/country lookups but I never used one.

I'm looking for small/clean solutions.
It's for helping someone filling out a form so it does not have to be 100% accurate.

Thanks in advance..

like image 207
Julian de Wit Avatar asked Aug 17 '09 12:08

Julian de Wit


1 Answers

You can make a simple HTTP request to this URL:

http://api.hostip.info/get_html.php?ip=207.46.197.32

using the value of the REMOTE_ADDR server variable. That will return the country and city like this:

Country: UNITED STATES (US)
City: New York, NY

I use that service for a web form just as you describe. Occasionally it doesn't know the answer, but usually it's very good (and it's free and simple 8-)

In C#, you can use System.Net.WebRequest.Create to read from the URL.

like image 193
RichieHindle Avatar answered Sep 21 '22 14:09

RichieHindle