• Stars
    star
    154
  • Rank 233,687 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Querying IP address information, support longitude and latitude. 快速查询IP信息,支持国内和国外IP信息查询,支持查询经纬度。

IPTools | 中文文档

Quickly query IP information, support domestic and foreign IP information query, support query latitude and longitude, and support geographical location to the city.

IPTools.China: nuget

IPTools.International: nuget

1. IPTools.China

Quickly query China IP information, country, province, city and network operators. Non China IP can only query national information.

(1) Install

Install-Package IPTools.China

(2) Download database file

https://github.com/stulzq/IPTools/raw/master/db/ip2region.db

After the database file is downloaded, put it in your project root directory (same level as the *.csprj file), and set the copy to the output directory.

1534995762038

At the beginning of version 1.2.0, the database file was unembedded into the assembly, which is convenient for updating and reduces the size of the assembly.

(3) Usage

IpTool.Search("your ip address");

eg.

var ipinfo = IpTool.Search("171.210.12.163");
Console.WriteLine(ipinfo.Country); // 中国
Console.WriteLine(ipinfo.Province); // 四川省
Console.WriteLine(ipinfo.City); // 成都市
Console.WriteLine(ipinfo.NetworkOperator);// 电信

(4) I18N

Not support . So you can't use IpTool.SearchWithI18NAsync().

(5) performance testing

Single thread double for loop queries 65025 IP, takes 170 ms.

(6) Custom DB path

IpToolSettings.ChinaDbPath="";

2. IPTools.International

Quickly query global IP information, support i18n, country, province, city, post code, longitude and latitude.

(1) Install

Install-Package IPTools.International

(2) Download database file

https://github.com/stulzq/IPTools/raw/master/db/GeoLite2-City.mmdb

After the database file is downloaded, put it in your project root directory (same level as the *.csprj file), and set the copy to the output directory.

1534995856116

At the beginning of version 1.2.0, the database file was unembedded into the assembly, which is convenient for updating and reduces the size of the assembly.

(3) Usage

IpTool.Search("your ip address");

eg.

var ipinfo = IpTool.SearchWithI18N("171.210.12.163");
Console.WriteLine(ipinfo.Country); // 中国
Console.WriteLine(ipinfo.CountryCode); // CN
Console.WriteLine(ipinfo.Province); // 四川省
Console.WriteLine(ipinfo.ProvinceCode); // SC
Console.WriteLine(ipinfo.City); // 成都
Console.WriteLine(ipinfo.Latitude); // 30.6667
Console.WriteLine(ipinfo.Longitude); // 104.6667
Console.WriteLine(ipinfo.AccuracyRadius);// 50

(4) I18N

IpTool.SearchWithI18N("your ip address");

eg.

var ipinfo = IpTool.SearchWithI18N("171.210.12.163","en");//If language code is not set, Chinese will be used by default.
Console.WriteLine(ipinfo.Country); // China
Console.WriteLine(ipinfo.CountryCode); // CN
Console.WriteLine(ipinfo.Province); // Sichuan
Console.WriteLine(ipinfo.ProvinceCode); // SC
Console.WriteLine(ipinfo.City); // Chengdu
Console.WriteLine(ipinfo.Latitude); // 30.6667
Console.WriteLine(ipinfo.Longitude); // 104.6667
Console.WriteLine(ipinfo.AccuracyRadius);// 50

Default language is chinese(zh-CN), How to change?

IpToolSettings.DefaultLanguage = "en";// set default language is english.

(5) Increase query speed

With the following settings, will double the query speed, the principle is to fully load the database file into the memory, the price is that the memory will increase 60-70M, space for time, this should be noted.

IpToolSettings.LoadInternationalDbToMemory = true;

Version >= 1.2.0

(6) performance testing

Single thread double for loop queries 65025 IP, takes 1500 ms(Memory).

(7) Custom DB path

IpToolSettings.InternationalDbPath="";

3. ASP.NET Core Support

IPTools provides an extension method for HttpContext.

usage:

HttpContext.GetRemoteIpInfo();
HttpContext.GetRemoteIpInfo(headerKey); // Get ip from header if you use nginx, haproxy etc.

4. Use both IPTools.China and IPTools.International

Both IPTools.China and IPTools.International implement IIpSearcher. The IpTool class will detect the package you installed during initialization and initialize it only once. IpTool has three static read-only properties, namely DefaultSearcher, IpChinaSearcher, IpAllSearcher.

  • DefaultSearcher. IpTool.Search() and IpTool.SearchWithI18N() will use the default Ip searcher.
  • IpChinaSearcher. IPTools.China Implemented searcher.
  • IpAllSearcher. IPTools.International Implemented searcher.

If you just installed IPTools.China then DefaultSearcher will be IpChinaSearcher and IpAllSearcher will be null.

If you just installed IPTools.International then DefaultSearcher will be IpAllSearcher and IpChinaSearcher will be null.

If you have both components installed at the same time, by default DefaultSearcher will be IpChinaSearcher, IpChinaSearcher and IpAllSearcher will not be null.

To change the default Searcher used by DefaultSearcher, please use the following code, if you have two components installed at the same time, it will take effect.

IpToolSettings.DefalutSearcherType = IpSearcherType.China;
IpToolSettings.DefalutSearcherType = IpSearcherType.International;

5. Referencing project

ip2region by lionsoul2014.

GeoIP2-dotnet by maxmind.

More Repositories

1

azure-openai-proxy

Azure OpenAI Service Proxy. Convert OpenAI official API request to Azure OpenAI API request. Support GPT-4,Embeddings,Langchain. Adapter from OpenAI to Azure OpenAI.
Go
1,177
star
2

IdentityServer4.Samples

Samples for IdentityServer4,use .net core 2.0
JavaScript
608
star
3

Alipay.Demo.PCPayment

支付宝PC网站支付、扫码支付 演示项目,实现支付、支付同步回调、支付异步通知、订单查询、退款、退款查询、订单关闭、扫码支付功能。采用支付宝服务端SDK:Alipay.AopSdk.Core,使用ASP.NET Core MVC 。
HTML
282
star
4

RSAUtil

.NET Core RSA algorithm using the help tool.It supports data encryption, decryption, signature and verification signature.It supports three key formats, namely: xml, pkcs1, pkcs8.It also supports key conversion for these three formats.Last also support pem formatting.
C#
273
star
5

dotnet-cnblogs-tool

博客园文章快捷发布工具
C#
166
star
6

HttpCode.Core

简单、易用、高效 一个有态度的开源.Net Http请求框架!可以用制作爬虫,api请求等等。
C#
158
star
7

RSAExtensions

.NET Core >=3.0 & .NET Standard >=2.2, RSA Enhanced Extension. Provide XML format key import and export. Unified export and import of PKCS # 1, PKCS # 8, and XML formats. Supports PKCS # 1, PKCS # 8 PEM import and export.
C#
149
star
8

SolutionRenamer

Fast rename solution,using .net core 2.0
C#
145
star
9

Hangfire.MySql.Core

Hangfire Mysql storage components, support for. NET core 1.1,. NET core 2.0,. NET standard 2.0. Based on Hangfire.MySqlStorage, some bugs were fixed and .NET standard 2.0 support was provided.
C#
83
star
10

ToolGood.Words.Core

一款高性能敏感词(非法词/脏字)检测过滤组件,附带繁体简体互换,支持全角半角互换,汉字转拼音,模糊搜索等功能。支持.net standard 2.0
C#
71
star
11

DotnetCore.RSA

.NET Core use RSA examples,implement RSA/RSA2's Encrypt,Decrypt,Sign,Verify Sign.Use OpenSsl's private/public key.
C#
69
star
12

UrlFirewall

UrlFirewall is a lightweight, fast filtering middleware for http request urls.It supports blacklist, whitelist mode.Supports persisting filter rules to any media.You can use it in webapi, gateway, etc.
C#
66
star
13

BlogDemos

C#
62
star
14

NConsul

.NET API for Consul (http://www.consul.io/)
C#
60
star
15

BlogTools

博文快速多渠道发布工具包,支持博客园、阿里云栖社区、腾讯云+社区、慕课网手记 4种渠道。
C#
36
star
16

AspNetCore.Authentication.ApiToken

A asp.net core webapi token authentication & generator open source library.
C#
32
star
17

DotnetRSA

DotnetRSA is a .NET Core Global Tool.Dotnet RSA Tool can help you generate xml pkcs1, pkcs8 three kinds of format keys, and supports three types of mutual conversion.
C#
27
star
18

dotnetcore-image

Solution of .NET Core GDI+(Image) on Linux/Docker
C#
21
star
19

QRConsole

Print QRCode to console.
C#
16
star
20

ClickHouse.DapperExtensions

Make ClickHouse available to Dapper
C#
14
star
21

NZookeeper

A zookeeper client library based on ZookeeperEx,easily use for Zookeeper.
C#
14
star
22

FreeCert

Fast and easy generation of HTTPS certificate library (Let's Encrypt ACME).
C#
13
star
23

EntityFrameworkCore2Demo

.NET Core控制台、ASP.NET Core程序使用EntityFrameworkCore 2.0示例,包括CodeFirst、DBFirst。详细文章介绍请看:http://www.cnblogs.com/stulzq/p/7717873.html
C#
12
star
24

Influxdb.BulkInsert

Influxdb asynchronous, fast and bulk insert components.Using HTTP or UDP protocol.Influxdb 异步、快速、批量插入组件,支持http和udp协议。
C#
11
star
25

CnBlogSubscribeTool

CnBlogSubscribeTool can crawl blog home page data at regular intervals.
C#
10
star
26

DynamicDns

动态DNS,支持多个云厂商。
C#
9
star
27

ChinaRegionCode

中华人民共和国县以上行政区划代码数据
C#
9
star
28

AspNetCoreHighConcurrency.Sample

AspNetCore High Concurrency Simple Code.Describes how to use distributed locking based on redis. Lock-free and queued commodity inventory operations.
C#
8
star
29

go-linecount

Fast text file line count tool.
Go
8
star
30

kong-plugin-rate-limiting-ex

Rate Limiting Ex is the rate limit plugin for kong gateway.Based on official rate-limiting plugin, I added a property that can be customized to get the request header for the ip address.
Lua
8
star
31

ClientUpdate

Update you c/s software
C#
7
star
32

hexo-deploy-agent

Go
7
star
33

EntityFramework-Core-Migrator

EntityFramework Core Migrator
C#
6
star
34

StudyRoad

6
star
35

MonitoringSystem

prometheus & grafana help doc.
5
star
36

JenkinsSharedLibraries

Jenkins Shared Libraries
Groovy
3
star
37

hexo-statistics

Go
3
star
38

DotNetActionsExample

.NET Github Action Example
C#
3
star
39

Damocles

Open source permission system.Under development now.
C#
3
star
40

MailHelper

C#
2
star
41

blog-demo-go

my blog's article demo
Go
2
star
42

WhoisClient

A simple domain whois lookup library.
C#
2
star
43

Visual-Studio-2013-Theme-Editor

Visual Studio 2013 Theme Editor
C#
1
star
44

TestJenkins

1
star
45

Zeta

A mysterious code repository.
C#
1
star
46

stulzq

1
star
47

WindowsRemoteDesktopCleanTool

Clean up windows remote desktop records
C#
1
star