Edi.ChinaDetector 1.2.251

dotnet add package Edi.ChinaDetector --version 1.2.251                
NuGet\Install-Package Edi.ChinaDetector -Version 1.2.251                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Edi.ChinaDetector" Version="1.2.251" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Edi.ChinaDetector --version 1.2.251                
#r "nuget: Edi.ChinaDetector, 1.2.251"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Edi.ChinaDetector as a Cake Addin
#addin nuget:?package=Edi.ChinaDetector&version=1.2.251

// Install Edi.ChinaDetector as a Cake Tool
#tool nuget:?package=Edi.ChinaDetector&version=1.2.251                

Edi.ChinaDetector

Detect if current code is running on China machine

Install

Install-Package Edi.ChinaDetector
dotnet add package Edi.ChinaDetector

Examples

Rank in the detection result indicates the possiblity that current code is running on a China machine, the higher the more possible. When using multiple detectors, if Rank >= 2 then you may consider the code is running on a China machine.

Offline Detection

By time zone

Not all regions in the +8 time zone use the name "China Standard Time" (CST).

For example, the +8 time zone also includes the following time zone names:

  • Australian Western Standard Time (AWST)
  • Singapore Time (SGT)
  • Hong Kong Time (HKT)
  • Malaysia Time (MYT)
  • Philippine Time (PHT)
  • Western Indonesian Time (WIB)
var service = new OfflineChinaDetectService();
var result = await service.Detect(DetectionMethod.TimeZone);
By culture
var service = new OfflineChinaDetectService();
var result = await service.Detect(DetectionMethod.Culture);
By behavior
var service = new OfflineChinaDetectService();
var result = await service.Detect(DetectionMethod.Behavior);
Multiple
var service = new OfflineChinaDetectService();
var result = await service.Detect(DetectionMethod.TimeZone | DetectionMethod.Culture);

or

await service.Detect(DetectionMethod.AllOffline);

Online Detection

Note

  • In China, IP address or GFW test is not a reliable way to detect if the machine is in China mainland, because many users are using VPN or proxy to access the Internet. Please use it in conjunction with offline detection.

  • In reality, please use HttpClientFactory or Typed HttpClient to create HttpClient as a best practice in .NET.

By IP
var handler = new HttpClientHandler
{
    UseProxy = false
};

var httpClient = new HttpClient(handler)
{
    Timeout = TimeSpan.FromSeconds(5)
};

var service = new OnlineChinaDetectService(httpClient);
await service.Detect(DetectionMethod.IPAddress);
By GFW test
var handler = new HttpClientHandler
{
    UseProxy = false
};

var httpClient = new HttpClient(handler)
{
    Timeout = TimeSpan.FromSeconds(5)
};

var service = new OnlineChinaDetectService(httpClient);
await service.Detect(DetectionMethod.GFWTest);

Dependency Injection

Coming in next release

免责申明

此项目(ChinaDetector)及其配套组件均为免费开源的产品,仅用于学习交流,并且不直接向中国提供服务,中国用户请于下载后立即删除。

任何中国境内的组织及个人不得使用此项目(ChinaDetector)及其配套组件构建任何形式的面向中国境内用户的网站或服务。

不可用于任何违反中华人民共和国(含台湾省)或使用者所在地区法律法规的用途。

因为作者即本人仅完成代码的开发和开源活动(开源即任何人都可以下载使用),从未参与用户的任何运营和盈利活动。

且不知晓用户后续将程序源代码用于何种用途,故用户使用过程中所带来的任何法律责任即由用户自己承担。

《开源软件有漏洞,作者需要负责吗?是的!》

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Edi.ChinaDetector:

Repository Stars
EdiWang/Moonglade
Blog system of https://edi.wang, runs on Microsoft Azure
Version Downloads Last updated
1.2.251 734 7/31/2024
1.1.251 776 2/4/2024
1.0.251 419 12/31/2023
0.9.251-beta.4 88 12/29/2023
0.8.251-beta.3 75 12/29/2023
0.7.251-beta.2 83 12/29/2023
0.6.251-beta.1 94 12/28/2023
0.5.251-preview.4 120 12/27/2023
0.4.251-preview.3 101 12/26/2023
0.3.251-preview.2 185 12/11/2023
0.2.251-preview.1 145 12/7/2023
0.1.251-preview.1 87 11/28/2023