我正在使用http://ipaddressextensions.codeplex.com/ dll库来检索客户的国家/地区,我正在使用以下代码。但结果总是显示“澳大利亚”,但我来自孟加拉国。任何人都可以使用该代码纠正我吗?
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
}
答案 0 :(得分:2)
这是示例源代码,其中IP地址被指定为常量。它不会查找您自己的IP地址!
string userHostIpAddress = "203.1.2.3"; // this is an Australian IP
您需要找到自己的IP并使用 。
例如,How to get the IP address of the server on which my C# application is running on?
中对此进行了解释