DataScript - avi.utils.get_geo_from_ip


Avi Vantage includes a geolocation database for identifying the origin of clients. This is a fixed database based on the MaxMind IP-country and IP-autonomous system number (ASN)data. The database is maintained on Avi Controllers and incorporates database updates when the Controllers are upgraded.
The DataScript function avi.utils.get_geo_from_ip is used to retrieve geolocation information , autonomous system (AS) number, country code, and location (latitude, longitude, region and city) of the queried IP address.
For more information on the geolocation database, refer to Geolocation Database.

Note: The database used for this API is equivalent to the default one maintained on the Avi Controller, it cannot be overridden or augmented with IP groups as mentioned in Geolocation Database.


Functions avi.utils.get_geo_from_ip(ip_string, [ flag ] )
Description The function returns geolocation information for a given IPv4/v6 address ip_string according to flag.
Prerequisites A minimum of 4GB RAM in the service engine
Parameter ip_string is a string containing the query IPv4/v6 address for a geodatabase inforamtion.
flag is a string set to "COUNTRY", "ASN" or "LOCATION", default as "COUNTRY" if none is provided.
Returns Returns nil if:
  • ip_string contains internal/invalid address, or
  • ip_string is not in the database (unassigned address), or
  • flag is set incorrectly (something other than "COUNTRY", "ASN" or "LOCATION"), or
  • extra shared memory is not properly configured for the SE group.

Returns a string containing an ISO 3166-1 alpha-2 country code (e.g., "AU" for Australia) if flag is set to "COUNTRY" or none provided
Returns a 32-bit ASN code (e.g., 1449 for AS1449 PayPal, Inc) if flag is set to "ASN"
Returns a table containing four string elements, latitude, longitude, region and city (e.g. ["44.9566", "34.1116", "Crimea", "Simferopol"]) if flag is set to "LOCATION"
The length for country code is limited to exact 2 characters, and region/city is capped to 36 characters respectively. </ul>

Configuring DataScript Function

To enable this function, at least 350MB of extra shared memory must be configured on the Service Engine group. To assign the extra memory, use the extra_shared_config_memory parameter in the SE group configuration.

[admin:example-ctrl]: > configure serviceenginegroup Default-Group extra_shared_config_memory 350
[admin:example-ctrl]: serviceenginegroup> save


  • Restart Service Engines in the group for the memory changes to take effect. To check whether database are loaded, refer to the /var/log/upstart/se_info.log directory in the SE.
  • If the shared memory is not set properly, all calls to this function will return nil.