{"id":20345469,"url":"https://github.com/linsir/lua-resty-ipip","last_synced_at":"2026-02-27T00:31:10.473Z","repository":{"id":87285315,"uuid":"79407453","full_name":"linsir/lua-resty-ipip","owner":"linsir","description":"ipip.net(17MonIP) parsing library for OpenResty.","archived":false,"fork":false,"pushed_at":"2018-06-04T08:49:46.000Z","size":1799,"stargazers_count":12,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-01T03:42:52.418Z","etag":null,"topics":["17monip","ngx-lua","openresty"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linsir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2017-01-19T02:35:05.000Z","updated_at":"2023-11-21T08:24:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"560c7132-eaaa-4a30-83b0-3e908407c467","html_url":"https://github.com/linsir/lua-resty-ipip","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/linsir/lua-resty-ipip","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linsir%2Flua-resty-ipip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linsir%2Flua-resty-ipip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linsir%2Flua-resty-ipip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linsir%2Flua-resty-ipip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linsir","download_url":"https://codeload.github.com/linsir/lua-resty-ipip/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linsir%2Flua-resty-ipip/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29878956,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T23:51:21.483Z","status":"ssl_error","status_checked_at":"2026-02-26T23:50:46.793Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["17monip","ngx-lua","openresty"],"created_at":"2024-11-14T22:08:37.660Z","updated_at":"2026-02-27T00:31:10.431Z","avatar_url":"https://github.com/linsir.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lua-resty-ipip\n\nlua-resty-ipip - ipip.net(17MonIP) parsing library for OpenResty.\n\n# Status\n\nReady for testing. Probably production ready in most cases, though not yet proven in the wild. Please check the issues list and let me know if you have any problems / questions.\n\n## Description\n\nIP query based on [http://www.ipip.net](http://www.ipip.net/), the best IP database for China.\n\n## Install\n    opm install pintsized/lua-resty-http\n    opm get linsir/lua-resty-ipip # use root\n\n## Synopsis\n\n````lua\n    lua_package_path \"/usr/local/openresty/demo/?.lua;;\";\n    lua_code_cache on;\n    resolver 223.5.5.5;\n    init_by_lua '\n        local ipip = require \"resty.ipip.client\"\n        cjson = require \"cjson\"\n        local opts = {\n            path = \"/path/to/17monipdb.datx\",\n            token = \"your token\",\n            timeout  = \"2000\",\n        }\n        ipipc = ipip:new(opts)\n    ';\n    server {\n        listen 8000;\n        charset utf-8;\n        # server_name ip.linsir.org;\n        default_type text/plain;\n        root /usr/local/openresty/nginx/html;\n\n        location /ip {\n            content_by_lua '\n                local ipipc = ipipc\n                local cjson = cjson\n                local res, err = ipipc:query_file(\"202.103.026.255\")\n                if not res then\n                    ngx.say(err)\n                    return\n                end\n                ngx.say(cjson.encode(res))\n            ';\n        }\n\n        location /free_api {\n            content_by_lua '\n                local ipipc = ipipc\n                local cjson = cjson\n                local res, err = ipipc:query_free_api(\"202.103.026.255\")\n                if not res then\n                    ngx.say(err)\n                    return\n                end\n                ngx.say(cjson.encode(res))\n            ';\n        }\n\n        location /api {\n            content_by_lua '\n                local ipipc = ipipc\n                local cjson = cjson\n                local res, err = ipipc:query_api(\"202.103.026.255\")\n                if not res then\n                    ngx.say(err)\n                    return\n                end\n                ngx.say(cjson.encode(res))\n            ';\n        }\n\n        location /api_status {\n            content_by_lua '\n                local ipipc = ipipc\n                local cjson = cjson\n                local res, err = ipipc:api_status()\n                # local res, err = ipipc:api_status(\"your token\")\n                if not res then\n                    ngx.say(err)\n                    return\n                end\n                ngx.say(cjson.encode(res))\n            ';\n        }\n\n        error_log  logs/ip_error.log info;\n    }\n\n}\n````\n\n- A typical output of the `/ip` location defined above is:\n\n```\n{\"country\":\"中国\",\"city\":\"武汉\",\"province\":\"湖北\"}\n```\n\n- A typical output of the `/free_api` location defined above is:\n\n```\n{\"place\":\"\",\"country\":\"中国\",\"city\":\"武汉\",\"province\":\"湖北\",\"carriers\":\"电信\"}\n```\n\n- A typical output of the `/api` location defined above is:\n\n```\n{\"carriers\":\"电信\",\"longitude\":\"114.298572\",\"city\":\"武汉\",\"province\":\"湖北\",\"china_area_code\":\"420100\",\"place\":\"\",\"country\":\"中国\",\"nation_code\":\"CN\",\"phone_code\":\"86\",\"tz_name\":\"Asia\\/Shanghai\",\"continents_code\":\"AP\",\"latitude\":\"30.584355\",\"tz_utc\":\"UTC+8\"}\n```\n\n- A typical output of the `/api_status` location defined above is:\n\n```\n{\"ret\":\"ok\",\"service\":{\"service_id\":10,\"expired\":\"2019-08-13\"},\"data\":{\"day\":1,\"hour\":1,\"limit\":false}}\n```\n\n# Methods\n\n## new\n\n`syntax: ipip:new(opts)`\n\n```\nlocal opts = {\n    path = \"/path/to/17monipdb.datx\",\n    token = \"your token\",\n    timeout  = \"2000\",\n}\nipipc = ipip:new(opts)\n\n```\n\n\n* `path`: Sets the 17monipdb.datx ([download free version](https://www.ipip.net/free_download/)) file path.\n* `token`: The token of ipip.net.\n* `timeout`: The timeout for http request.\n\n\n## query\n\n`syntax: res, err = ipipc:query(ip)`\n```\ndata, err = ipipc:query_free_api(ip)\ndata, err = ipipc:query_api(ip)\ndata, err = ipipc:query_file(ip)\n\n```\n\n## api status\n\n```\ndata, err = ipipc:api_status()\ndata, err = ipipc:api_status(\"9a8bc1a059db4a14b4feb0f38db38bbf4d5353ab1\")\n```\n\n# Author\n\nLinsir \u003croot@linsir.org\u003e\n\n# Licence\n\nThis module is licensed under the 2-clause BSD license.\n\nCopyright (c) 2017, Linsir \u003croot@linsir.org\u003e\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinsir%2Flua-resty-ipip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinsir%2Flua-resty-ipip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinsir%2Flua-resty-ipip/lists"}