Question

I am using the http://ipaddressextensions.codeplex.com/ dll library for retrieving client's country and I am using the following code. But the result always show "Australia" but I am from Bangladesh. Can anybody correct me using that code?

using System.Net;
using WorldDomination.Net;

string userHostIpAddress = "203.1.2.3";
IPAddress ipAddress;
if (IPAddress.TryParse(userHostIpAddress, out ipAddress))
{
    string country = ipAddress.Country(); // return value: UNITED STATES
    string iso3166TwoLetterCode = ipAddress.Iso3166TwoLetterCode(); // return value: US
}
Was it helpful?

Solution

This is sample source code, in which the IP address is specified as a constant. It does not look up your own IP address!

string userHostIpAddress = "203.1.2.3"; // this is an Australian IP

You need to find your own IP and use that.

For example, this is explained in How to get the IP address of the server on which my C# application is running on?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top