{"id":17871231,"url":"https://github.com/stulzq/iptools","last_synced_at":"2025-03-21T16:31:19.907Z","repository":{"id":95704691,"uuid":"145274003","full_name":"stulzq/IPTools","owner":"stulzq","description":"Querying IP address information, support longitude and latitude. 快速查询IP信息，支持国内和国外IP信息查询，支持查询经纬度。","archived":false,"fork":false,"pushed_at":"2019-12-04T03:14:53.000Z","size":65168,"stargazers_count":167,"open_issues_count":1,"forks_count":41,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-10-02T07:53:20.509Z","etag":null,"topics":["ip"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stulzq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-19T04:51:34.000Z","updated_at":"2024-09-18T01:27:50.000Z","dependencies_parsed_at":"2023-03-09T13:00:20.884Z","dependency_job_id":null,"html_url":"https://github.com/stulzq/IPTools","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FIPTools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FIPTools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FIPTools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FIPTools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stulzq","download_url":"https://codeload.github.com/stulzq/IPTools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221816943,"owners_count":16885423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ip"],"created_at":"2024-10-28T10:27:42.604Z","updated_at":"2024-10-28T10:27:43.229Z","avatar_url":"https://github.com/stulzq.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IPTools | [中文文档](README_zh-CN.md)\nQuickly query IP information, support domestic and foreign IP information query, support query latitude and longitude, and support geographical location to the city.\n\nIPTools.China: [![nuget](https://img.shields.io/nuget/v/IPTools.China.svg?style=flat-square)](https://www.nuget.org/packages/IPTools.China/)\n\nIPTools.International: [![nuget](https://img.shields.io/nuget/v/IPTools.International.svg?style=flat-square)](https://www.nuget.org/packages/IPTools.International/)\n\n## 1. IPTools.China\n\nQuickly query China IP information, country, province, city and network operators. Non China IP can only query national information.\n\n### (1) Install\n\n````shell\nInstall-Package IPTools.China\n````\n\n### (2) Download database file\n\n```shell\nhttps://github.com/stulzq/IPTools/raw/master/db/ip2region.db\n```\n\nAfter 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**.\n\n![1534995762038](assets/1534995762038.png)\n\n\u003e 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.\n\n### (3) Usage\n\n````shell\nIpTool.Search(\"your ip address\");\n````\n\neg.\n\n````csharp\nvar ipinfo = IpTool.Search(\"171.210.12.163\");\nConsole.WriteLine(ipinfo.Country); // 中国\nConsole.WriteLine(ipinfo.Province); // 四川省\nConsole.WriteLine(ipinfo.City); // 成都市\nConsole.WriteLine(ipinfo.NetworkOperator);// 电信\n````\n\n### (4) I18N\n\nNot support . So you can't use `IpTool.SearchWithI18NAsync()`.\n\n### (5) performance testing\n\nSingle thread double for loop queries 65025 IP, takes 170 ms.\n\n### (6) Custom DB path\n\n````csharp\nIpToolSettings.ChinaDbPath=\"\";\n````\n\n## 2. IPTools.International\n\nQuickly query global IP information, support i18n, country, province, city, post code, longitude and latitude. \n\n### (1) Install\n\n```shell\nInstall-Package IPTools.International\n```\n\n### (2) Download database file\n\n```shell\nhttps://github.com/stulzq/IPTools/raw/master/db/GeoLite2-City.mmdb\n```\n\nAfter 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**.\n\n![1534995856116](assets/1534995856116.png)\n\n\u003e 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.\n\n### (3) Usage\n\n````csharp\nIpTool.Search(\"your ip address\");\n````\n\neg.\n\n````csharp\nvar ipinfo = IpTool.SearchWithI18N(\"171.210.12.163\");\nConsole.WriteLine(ipinfo.Country); // 中国\nConsole.WriteLine(ipinfo.CountryCode); // CN\nConsole.WriteLine(ipinfo.Province); // 四川省\nConsole.WriteLine(ipinfo.ProvinceCode); // SC\nConsole.WriteLine(ipinfo.City); // 成都\nConsole.WriteLine(ipinfo.Latitude); // 30.6667\nConsole.WriteLine(ipinfo.Longitude); // 104.6667\nConsole.WriteLine(ipinfo.AccuracyRadius);// 50\n````\n\n### (4) I18N\n\n````csharp\nIpTool.SearchWithI18N(\"your ip address\");\n````\n\neg.\n\n````csharp\nvar ipinfo = IpTool.SearchWithI18N(\"171.210.12.163\",\"en\");//If language code is not set, Chinese will be used by default.\nConsole.WriteLine(ipinfo.Country); // China\nConsole.WriteLine(ipinfo.CountryCode); // CN\nConsole.WriteLine(ipinfo.Province); // Sichuan\nConsole.WriteLine(ipinfo.ProvinceCode); // SC\nConsole.WriteLine(ipinfo.City); // Chengdu\nConsole.WriteLine(ipinfo.Latitude); // 30.6667\nConsole.WriteLine(ipinfo.Longitude); // 104.6667\nConsole.WriteLine(ipinfo.AccuracyRadius);// 50\n````\n\nDefault language is chinese(zh-CN), How to change?\n\n````csharp\nIpToolSettings.DefaultLanguage = \"en\";// set default language is english.\n````\n\n### (5) Increase query speed\n\nWith 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.\n\n```csharp\nIpToolSettings.LoadInternationalDbToMemory = true;\n```\n\n\u003e Version \u003e= 1.2.0\n\n### (6) performance testing\n\nSingle thread double for loop queries 65025 IP, takes 1500 ms(Memory).\n\n### (7) Custom DB path\n\n````csharp\nIpToolSettings.InternationalDbPath=\"\";\n````\n\n## 3. ASP.NET Core Support\n\nIPTools provides an extension method for `HttpContext`.\n\nusage:\n\n````csharp\nHttpContext.GetRemoteIpInfo();\nHttpContext.GetRemoteIpInfo(headerKey); // Get ip from header if you use nginx, haproxy etc.\n````\n\n## 4. Use both IPTools.China and IPTools.International\n\nBoth 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`.\n\n- `DefaultSearcher`. `IpTool.Search()` and `IpTool.SearchWithI18N()` will use the default Ip searcher.\n- `IpChinaSearcher`. IPTools.China Implemented searcher.\n- `IpAllSearcher`. IPTools.International Implemented searcher.\n\nIf you just installed IPTools.China then `DefaultSearcher` will be `IpChinaSearcher` and `IpAllSearcher` will be null.\n\nIf you just installed IPTools.International then `DefaultSearcher` will be `IpAllSearcher` and `IpChinaSearcher` will be null.\n\nIf you have both components installed at the same time, by default `DefaultSearcher` will be `IpChinaSearcher`, `IpChinaSearcher` and `IpAllSearcher` will not be null.\n\nTo 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.\n\n```csharp\nIpToolSettings.DefalutSearcherType = IpSearcherType.China;\nIpToolSettings.DefalutSearcherType = IpSearcherType.International;\n```\n\n## 5. Referencing project\n\n[**ip2region**](https://github.com/lionsoul2014/ip2region) by [lionsoul2014](https://github.com/lionsoul2014).\n\n[**GeoIP2-dotnet**](https://github.com/maxmind/GeoIP2-dotnet) by [maxmind](https://github.com/maxmind).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstulzq%2Fiptools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstulzq%2Fiptools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstulzq%2Fiptools/lists"}