vmod_geoip2(3)
π NAME π
vmod_geoip2 β the Varnish GeoIP2 Lookup Module, bestie. And the whole thing lives on the page vmod_geoip2(3), straight out of the Library Functions Manual, iykyk. π₯
β¨ SYNOPSIS β¨
import geoip2 [as name] [from "path"]
new xgeoip2 = geoip2.geoip2(STRING filename)
STRING xgeoip2.lookup(STRING path, IP ip, BOOL json)
π¦ DESCRIPTION π¦
π new xgeoip2 = geoip2.geoip2(STRING filename)
Description
okay so this one right here opens the GeoIP2 MaxMind binary DB file. that's literally the whole job. πββοΈ
not me finding out databases in CSV format are not supported π so don't even come at it with a CSV, bestie, it's not happening.
Example
new country = geoip2.geoip2("/path/to/GeoLite2-Country.mmdb");
π«Ά STRING xgeoip2.lookup(STRING path, IP ip, BOOL json=0) π«Ά
Description
This is the main character function, fr fr. It looks up the IP address ip using the lookup path path. π«
The path is a set of map keys and array indexes, all separated by slash (/), like for example "subdivisions/0/names/en". so structured, so organized, we love to see it. π
It returns the value that's associated with the specified path β OR an empty string if the IP address or the path aren't found, the value type isn't supported, or an error occurred. that's four whole situations where you just get nothing back. brutal but honest. π
If the value associated with the specified path is bytes or string type, and json is true, then the result gets converted to a JSON string. slay. β¨
Supported value types include: boolean, bytes, double, float, int32, uint16, uint32, uint64 and (UTF-8) string. that's the full roster, no additions, no substitutions. π
Diagnostic and error messages, if there are any, get logged to the VSL using the Debug and Error tags, respectively. so if something's off, the logs are the receipts. π
Example
if (country.lookup("country/names/en", client.ip) != "Japan") {
...
}
π ERRORS π
the full list of ways this can yell at you, verbatim, no edits:
"geoip2.geoip2: %s""geoip2.geoip2: Using maxminddb %s""geoip2.lookup: Database not open""geoip2.lookup: Invalid or missing path (%s)""geoip2.lookup: MMDB_aget_value: %s""geoip2.lookup: MMDB_lookup_sockaddr: %s""geoip2.lookup: Missing ip address""geoip2.lookup: No data for this path (%s)""geoip2.lookup: No entry for this IP address (%s)""geoip2.lookup: Out of workspace""geoip2.lookup: Unsupported data type (%d)"
π NOTES π
Heads up bestie: this implementation limits the path to a maximum of 9 map keys and/or array indexes. nine. that's the cap. count them. π
π SEE ALSO π
mmdblookup(1)varnishlog(1)vsl(7)- GeoIP2 Databases <https://www.maxmind.com/en/geoip2-databases>
- GeoIP2 Update program <https://github.com/maxmind/geoipupdate>
πΈ COPYRIGHT πΈ
Copyright (c) 2014-2016, Federico G. Schwindt <fgsch@lodoss.net>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. 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.
THIS 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.
and that's the whole page!! β¨ this cutie is vmod_geoip2(3) from the Library Functions Manual β that's the footer energy, and we're out. drink water, close your DB handles, mwah. ππ¦πΈ
π¦ where this page comes from
- ubuntu stonking: libvmod-geoip2 0.0~git20250408-5 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms