{"id":13896756,"url":"https://github.com/leafo/luajit-geoip","last_synced_at":"2025-07-22T06:07:41.017Z","repository":{"id":44572778,"uuid":"67219345","full_name":"leafo/luajit-geoip","owner":"leafo","description":"luajit bindings to maxmind geoip","archived":false,"fork":false,"pushed_at":"2023-05-03T09:07:55.000Z","size":46,"stargazers_count":21,"open_issues_count":1,"forks_count":6,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-23T08:13:51.163Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"MoonScript","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/leafo.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}},"created_at":"2016-09-02T12:05:50.000Z","updated_at":"2024-09-09T12:40:42.000Z","dependencies_parsed_at":"2024-11-09T13:46:38.027Z","dependency_job_id":null,"html_url":"https://github.com/leafo/luajit-geoip","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/leafo/luajit-geoip","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fluajit-geoip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fluajit-geoip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fluajit-geoip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fluajit-geoip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leafo","download_url":"https://codeload.github.com/leafo/luajit-geoip/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fluajit-geoip/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266437378,"owners_count":23928238,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-08-06T18:03:08.174Z","updated_at":"2025-07-22T06:07:40.994Z","avatar_url":"https://github.com/leafo.png","language":"MoonScript","funding_links":[],"categories":["MoonScript"],"sub_categories":[],"readme":"\n# LuaJIT bindings to MaxMind's GeoIP and GeoIP2 (libmaxminddb) libraries\n\n* https://github.com/maxmind/libmaxminddb\n* https://github.com/maxmind/geoip-api-c \u0026mdash; legacy library\n\nIn order to use this library you'll need LuaJIT, the GeoIP library you're\ntrying to use, and the databases files for the appropriate library. You should\nbe able to find these in your package manager.\n\n**I recommend using libmaxminddb**, as the legacy GeoIP databases are no\nlonger updated.\n\n## Install\n\n```bash\nluarocks install luajit-geoip\n```\n\n# Reference\n\n## libmaxminddb\n\nThe module is named `geoip.mmdb`\n\n```lua\nlocal geoip = require \"geoip.mmdb\"\n```\n\nThis module works great in OpenResty. You'll want to keep references to loaded\nGeoIP DB objects at the module level, in order avoid reloading the DB on every\nrequest. \n\n\u003cdetails\u003e\n\n\u003csummary\u003eSee OpenResty example\u003c/summary\u003e\n\nCreate a new module for your GeoIP databases:\n\n**`geoip_helper.lua`**\n\n```lua\nlocal geoip = require \"geoip.mmdb\"\n\nreturn {\n  country_db = assert(geoip.load_database(\"/var/lib/GeoIP/GeoLite2-Country.mmdb\")),\n  -- load more databases if necessary:\n  -- asnum_db = ...\n  -- etc.\n}\n```\n\n**OpenResty request handler:**\n\n```lua\n-- this module will be cached in `package.loaded`, and the databases will only be loaded on first access\nlocal result = require(\"geoip_helper\").country_db:lookup(ngx.var.remote_addr)\nif result then\n  ngx.say(\"Your country:\" .. result.country.iso_code)\nend\n```\n\n\u003e **Note:** If you're using a proxy with x-forwarded-for you'll need to adjust\n\u003e how you access the user's IP address\n\n\u003c/details\u003e\n\n\n### `db, err = load_database(file_name)`\n\nLoad the database from the file path. Returns `nil` and error message if the\ndatabase could not be loaded.\n\nThe location of database files vary depending on the system and type of\ndatabase. For this example we'll use the country database located at\n`/var/lib/GeoIP/GeoLite2-Country.mmdb`.\n\n\n```lua\nlocal mmdb = assert(geoip.load_database(\"/var/lib/GeoIP/GeoLite2-Country.mmdb\"))\n```\n\nThe database object has the following methods:\n\n\n### `object, err = mmdb:lookup(address)`\n\n```lua\nlocal result = assert(mmdb:lookup(\"8.8.8.8\"))\n\n-- print the country code \nprint(result.country.iso_code) --\u003e US\n```\n\nLook up an address (as a string), and return all data about it as a Lua table.\nReturns `nil` and an error if the address could not be looked up, or there was\nno information for that address.\n\n\u003e Note: You can lookup both ipv4 and ipv6 addresses\n\nThe structure of the output depends on the database used. (It matches the\nstructure of the out from the `mmdblookup` utility, if you need a quick way to\ncheck)\n\n### `value, err = mmdb:lookup_value(address, ...)`\n\n```lua\n-- prints the country code\nprint(assert(mmdb:lookup_value(\"8.8.8.8\", \"country\", \"iso_code\"))) --\u003e US\n```\n\nLooks up a single value for an address using the path specified in the varargs\n`...`. Returns `nil` and an error if the address is invalid or a value was not\nlocated at the path. This method avoids scanning the entire object for an\naddress's entry, so it may be more efficient if a specific value from the\ndatabase is needed.\n\n\n## geoip \u0026mdash; legacy\n\n*The databases for this library are no longer updated, I strongly recommend\nusing the mmdb functionality above*\n\nThe module is named `geoip`\n\n```lua\nlocal geoip = require \"geoip\"\n```\n\nGeoIP has support for many different database types.  The available lookup\ndatabases are automatically loaded from the system location.\n\nOnly the country and ASNUM databases are supported. Feel free to create a pull\nrequest with support for more.\n\n### `res, err = lookup_addr(ip_address)`\n\nLook up information about an address. Returns an table with properties about\nthat address extracted from all available databases.\n\n\n```lua\nlocal geoip = require \"geoip\"\nlocal res = geoip.lookup_addr(\"8.8.8.8\")\n\nprint(res.country_code)\n```\n\nThe structure of the return value looks like this:\n\n```lua\n{\n  country_code = \"US\",\n  country_name = \"United States\",\n  asnum = \"AS15169 Google Inc.\"\n}\n```\n\n### Controlling database caching\n\nYou can control how the databases are loaded by manually instantiating a\n`GeoIP` object and calling the `load_databases` method directly. `lookup_addr`\nwill automatically load databases only if they haven't been loaded yet.\n\n```lua\nlocal geoip = require(\"geoip\")\n\nlocal gi = geoip.GeoIP()\ngi:load_databases(\"memory\")\n\nlocal res = gi:lookup_addr(\"8.8.8.8\")\n```\n\n\u003e By default the STANDARD mode is used, which reads from disk for each lookup\n\n\n# Version history\n\n\n* **2.1** *(Aug 28, 2020)* \u0026mdash; Fix bug with parsing booleans from mmdb ([#3](https://github.com/leafo/luajit-geoip/pull/3)) michaeljmartin \n* **2.0** *(Apr 6, 2020)* \u0026mdash; Support for mmdb (libmaxminddb), fix memory leak in geoip\n* **1.0** *(Apr 4, 2018)* \u0026mdash; Initial release, support for geoip\n\n# Contact\n\nLicense: MIT, Copyright 2020\nAuthor: Leaf Corcoran (leafo) ([@moonscript](http://twitter.com/moonscript))  \nEmail: leafot@gmail.com  \nHomepage: \u003chttp://leafo.net\u003e  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Fluajit-geoip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleafo%2Fluajit-geoip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Fluajit-geoip/lists"}