Geo Lookup Plugin
Lookup geolocation by IP address or domain name
Syntax Rules
Add
%GEOLOOKUP{"host" format="..."}% anywhere in a TWiki page or skin template.
Parameters:
-
"host": Host IP address (example: "75.52.124.86") or host name (example: "twiki.org")
-
format="...": Format of geolocation, optional. Default is "$city, $region, $country_name". Supported variables:
-
$latitude: Latitude
-
$longitude: Longitude
-
$city: City name
-
$region: Region name
-
$country_name: Country name
-
$country_code: Two letter country code
-
$postal_code: Postal code (USA only)
-
$metro_code: Metropolitan code
(USA only)
-
$area_code: Telephone area code (USA only)
Examples:
-
%GEOLOOKUP{"75.52.124.86"}% shows default format Sunnyvale, CA, USA
-
%GEOLOOKUP{"75.52.124.86" format="$latitude, $longitude"}% shows comma separated latitude and longitude
Usage Examples
Form to query geo-location by IP address
Example: (works properly if plugin is installed and enabled)
Where are people who register in TWiki?
As a TWiki administrator, you can get location information of people registering in TWiki. In
twiki/templates/registernotifyadmin.tmpl write this:
%WIKINAME% has been registered with %EMAILADDRESS%, %REMOTE_ADDR%, %GEOLOOKUP{%REMOTE_ADDR%}%
Where am I connecting to the internet?
Show visitors where they connect to the internet. For example, write this:
http://maps.google.com/maps?z=12&ll=%ENCODE{%GEOLOOKUP{"%REMOTE_ADDR%" format="$latitude,$longitude"}%}%
to get this link: (renders properly if plugin is installed and enabled)
http://maps.google.com/maps?z=12&ll=40.2997%2c-111.6737
Alternatively, in a similar way, show a map embedded in a TWiki page.
Plugin Settings
Plugin settings are stored as preferences variables. To reference a plugin setting write
%<plugin>_<setting>%, such as
%GEOLOOKUPPLUGIN_SHORTDESCRIPTION%
- One line description, is shown in the TextFormattingRules topic:
- Set SHORTDESCRIPTION = Lookup geolocation by IP address or domain name
Plugin Installation Instructions
Note: You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the TWiki server.
- Download the ZIP file from the Plugin Home (see below)
- Unzip
GeoLookupPlugin.zip in your twiki installation directory. Content: | File: | Description: |
data/TWiki/GeoLookupPlugin.txt | Plugin topic |
data/TWiki/VarGEOLOOKUP.txt | Variable documentation |
lib/TWiki/Plugins/GeoLookupPlugin.pm | Plugin Perl module |
pub/TWiki/GeoLookupPlugin/twiki-logo-80x40-t.gif | Branding icon |
- Configure the Plugin:
- Run the configure script to enable the Plugin
- Install CPAN:MaxMind::DB::Reader
- Download the free GeoIP database:
Visit https://dev.maxmind.com/geoip/geoip2/geolite2/
and download GeoLite2 City MaxMind DB binary, gzipped, or:
cd /usr/share/GeoIP
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
tar -xzf GeoLite2-City.tar.gz
cp -p GeoLite2-City_20190430/GeoLite2-City.mmdb .
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz
tar -xzf GeoLite2-Country.tar.gz
cp -p GeoLite2-Country_20190430/GeoLite2-City.mmdb .
- Hint: Install a cron to refresh the geo database once a month on the second day of the month
- Note: The GeoIP database is assumed to be
/usr/share/GeoIP/GeoLite2-City.mmdb. For non-standard location define a $TWiki::cfg{GeoLookupPlugin}{GeoDataFile} configure setting in twiki/lib/LocalSite.cfg
- Test if the installation was successful:
-
%GEOLOOKUP{"216.58.216.96"}% returns: Bluffdale, Utah, United States
Plugin Info
This plugin refers to GeoLite data created by MaxMind, available from
http://www.maxmind.com/
.
Related Topics: VarGEOLOOKUP,
TWikiPlugins,
DeveloperDocumentationCategory,
AdminDocumentationCategory,
TWikiPreferences