RC1*_*140 18 .net c# geolocation
我如何确定特定IP地址源自使用c#的国家/地区.我需要使用它来检查连接是否来自特定国家/地区.
Ron*_*Ron 26
您可以在项目中使用此SQL数据来确定:IP地址地理定位SQL数据库.下载该数据并将其导入数据库以在本地运行检查.
或者您可以使用他们的免费API返回包含国家/地区代码和国家/地区名称的XML.您将使用您要检查的IP地址向以下URL发出请求,如下例所示:
http://ipinfodb.com/ip_query_country.php?ip=74.125.45.100
返回:
<Response>
<Ip>74.125.45.100</Ip>
<Status>OK</Status>
<CountryCode>US</CountryCode>
<CountryName>United States</CountryName>
</Response>
Run Code Online (Sandbox Code Playgroud)
只是一个简单的API调用,例如https://ipapi.co/8.8.8.8/country/
我们
这是一个工作提琴的C#示例:
using System;
using System.Net;
using System.IO;
using System.Text;
public class Program
{
public static void Main()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://ipapi.co/8.8.8.8/country/");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var reader = new System.IO.StreamReader(response.GetResponseStream(), ASCIIEncoding.ASCII);
Console.WriteLine(reader.ReadToEnd());
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19945 次 |
| 最近记录: |