{"id":19829679,"url":"https://github.com/workbunny/webman-ip-attribution","last_synced_at":"2025-09-08T01:32:34.116Z","repository":{"id":59401958,"uuid":"536982793","full_name":"workbunny/webman-ip-attribution","owner":"workbunny","description":"🚀🐇 Webman plugin for IP attribution query. ","archived":false,"fork":false,"pushed_at":"2024-07-05T08:56:31.000Z","size":466768,"stargazers_count":24,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-12-26T23:05:32.401Z","etag":null,"topics":["geolite2","php","webman","workbunny"],"latest_commit_sha":null,"homepage":"https://www.workerman.net/plugin/88","language":"PHP","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/workbunny.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}},"created_at":"2022-09-15T10:52:44.000Z","updated_at":"2024-12-16T03:03:01.000Z","dependencies_parsed_at":"2023-01-30T02:31:23.867Z","dependency_job_id":null,"html_url":"https://github.com/workbunny/webman-ip-attribution","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workbunny%2Fwebman-ip-attribution","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workbunny%2Fwebman-ip-attribution/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workbunny%2Fwebman-ip-attribution/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workbunny%2Fwebman-ip-attribution/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/workbunny","download_url":"https://codeload.github.com/workbunny/webman-ip-attribution/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232271900,"owners_count":18497768,"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":["geolite2","php","webman","workbunny"],"created_at":"2024-11-12T11:19:33.122Z","updated_at":"2025-01-03T00:09:58.982Z","avatar_url":"https://github.com/workbunny.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg width=\"260px\" src=\"https://chaz6chez.cn/images/workbunny-logo.png\" alt=\"workbunny\"\u003e\u003c/p\u003e\n\n**\u003cp align=\"center\"\u003eworkbunny/webman-ip-attribution\u003c/p\u003e**\n\n**\u003cp align=\"center\"\u003e🐇  Webman plugin for IP attribution query. 🐇\u003c/p\u003e**\n\n# Webman plugin for IP attribution query.\n\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://github.com/workbunny/webman-ip-attribution/actions\"\u003e\n        \u003cimg src=\"https://github.com/workbunny/webman-ip-attribution/actions/workflows/CI.yml/badge.svg\" alt=\"Build Status\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/workbunny/webman-ip-attribution/releases\"\u003e\n        \u003cimg alt=\"Latest Stable Version\" src=\"https://badgen.net/packagist/v/workbunny/webman-ip-attribution/latest\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/workbunny/webman-ip-attribution/blob/main/composer.json\"\u003e\n        \u003cimg alt=\"PHP Version Require\" src=\"https://badgen.net/packagist/php/workbunny/webman-ip-attribution\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/workbunny/webman-ip-attribution/blob/main/LICENSE\"\u003e\n        \u003cimg alt=\"GitHub license\" src=\"https://badgen.net/packagist/license/workbunny/webman-ip-attribution\"\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n\n## 简介\n\n- 该插件自带ip本地库，存放于`/database`； 最后更新时间：2024-07-05 **(空了就时不时更新一下)** \n  - **注：由于db文件比较大，强烈建议外载**\n    1. 至 https://www.maxmind.com/ 注册账号\n    2. 进入下载页面下载对应db文件\n- `webman-ip-attribution` 是基于`geoip2`作为底层，依托 `mmdb数据库` 查询ip归属地及asn信息\n- 本项目基于[geoip2/geoip2](https://github.com/maxmind/GeoIP2-php)，感谢[MaxMind](https://github.com/maxmind) 工作组的开源\n\n## 安装\n```shell\ncomposer require workbunny/webman-ip-attribution\n```\n## 使用\n\n### 配置\n\n#### 1. 在Webman中使用app.php\n\n**注：配置可选填**\n\n```php\nreturn [\n    'enable' =\u003e true,\n    \n    'default'  =\u003e '--',      // 缺省展示值\n    'language' =\u003e ['zh-CN'], // 语言\n\n    'db-country' =\u003e null,    // 自定义的country库绝对地址\n    'db-city'    =\u003e null,    // 自定义的city库绝对地址\n    'db-asn'     =\u003e null,    // 自定义的asn库绝对地址\n];\n```\n\n#### 2. 在php-fpm中使用\n\n**注：配置可选填**\n\n```php\nuse Workbunny\\WebmanIpAttribution\\Location;\n\n$location = new Location([\n    'default'  =\u003e '--',      // 缺省展示值\n    'language' =\u003e ['zh-CN'], // 语言\n    'db-country' =\u003e null,    // 自定义的country库绝对地址\n    'db-city'    =\u003e null,    // 自定义的city库绝对地址\n    'db-asn'     =\u003e null,    // 自定义的asn库绝对地址\n]);\n```\n\n### 快速获取\n```php\nuse Workbunny\\WebmanIpAttribution\\Location;\nuse Workbunny\\WebmanIpAttribution\\Exceptions\\IpAttributionException\n\ntry {\n     $location = new Location();\n     var_dump($location-\u003egetLocation('8.8.8.8')); // ipv4\n     var_dump($location-\u003egetLocation('::0808:0808')); // ipv6\n//     [\n//         'country' =\u003e 'United States',\n//         'city' =\u003e '--',\n//         'asn' =\u003e 'GOOGLE',\n//         'continent' =\u003e 'North America',\n//         'timezone' =\u003e 'America/Chicago',\n//     ]\n }catch (IpAttributionException $exception){\n \n }\n```\n\n### 使用city库查询\n\n**注：City库包含了 大洲、国家、城市，但不包含网络运营商等相关信息**\n\n```php\nuse Workbunny\\WebmanIpAttribution\\Location;\nuse Workbunny\\WebmanIpAttribution\\Exceptions\\IpAttributionException\n\ntry {\n   $location = new Location();\n    var_dump($location-\u003ecity('8.8.8.8')); // ipv4\n    var_dump($location-\u003ecity('::0808:0808')); // ipv6\n    // 返回 GeoIp2\\Model\\City 对象\n    \n }catch (IpAttributionException $exception){\n \n }\n```\n\n### 使用country库查询\n\n**注：Country库不包含城市及网络运营商等信息，通常使用City库即可，Country存在的意义在于较于City更轻**\n\n```php\nuse Workbunny\\WebmanIpAttribution\\Location;\nuse Workbunny\\WebmanIpAttribution\\Exceptions\\IpAttributionException\n\ntry {\n   $location = new Location();\n    var_dump($location-\u003ecountry('8.8.8.8')); // ipv4\n    var_dump($location-\u003ecountry('::0808:0808')); // ipv6\n    // 返回 GeoIp2\\Model\\Country 对象\n    \n }catch (IpAttributionException $exception){\n \n }\n```\n\n### 使用asn库查询\n\n**注：Asn库仅包含网络运营商等相关信息**\n\n```php\nuse Workbunny\\WebmanIpAttribution\\Location;\nuse Workbunny\\WebmanIpAttribution\\Exceptions\\IpAttributionException\n\ntry {\n   $location = new Location();\n    var_dump($location-\u003easn('8.8.8.8')); // ipv4\n    var_dump($location-\u003easn('::0808:0808')); // ipv6\n    // 返回 GeoIp2\\Model\\Asn 对象\n    \n }catch (IpAttributionException $exception){\n \n }\n```\n\n### 使用原始Reader操作\n\n**注：原始Reader可以直接使用 [geoip2/geoip2](https://github.com/maxmind/GeoIP2-php) 提供的方法操作相关的库**\n\n```php\nuse Workbunny\\WebmanIpAttribution\\Location;\n\n$location = new Location();\nvar_dump($location-\u003ecreateReader(Location::DB_CITY)); // City库\n// 返回连接City库的 GeoIp2\\Database\\Reader 对象\nvar_dump($location-\u003ecreateReader(Location::DB_ASN)); // ASN库\n// 返回连接ASN库的 GeoIp2\\Database\\Reader 对象   \nvar_dump($location-\u003ecreateReader(Location::DB_ASN)); // Country库\n// 返回连接Country库的 GeoIp2\\Database\\Reader 对象\n```\n\n更多用法和示例参照 [geoip2/geoip2](https://github.com/maxmind/GeoIP2-php)；\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkbunny%2Fwebman-ip-attribution","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkbunny%2Fwebman-ip-attribution","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkbunny%2Fwebman-ip-attribution/lists"}