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.


  • 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.

  • Starting with NSX Advanced Load Balancer version 21.1.1, it is mandatory to attach System-GeoDB profile to the VS Datascripts that make use of the function get_geo_from_ip.

  • The VSDataScriptSet that contains the DataScript using this function must refer to 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", "LOCATION", or "ALL" 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", "LOCATION", or "ALL"), or

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"
Returns a table containing all geo information available, along with any user mapping matches, for the target IP if flag is set to “ALL“, for example:

      [“ATTRIBUTE_COUNTRY_NAME“] = “United States“,
      [“ATTRIBUTE_CONTINENT_NAME“] = “North America“,
      [“ATTRIBUTE_LATITUDE“] = “37.3583“,
      [“ATTRIBUTE_LONGITUDE“] = “-122.1081“,
      [“ATTRIBUTE_USER_DEFINED_MAPPING“] = { [1] = “Example Mapping 1“, [2] = “Example Mapping 2", etc. }

The length for country code is limited to exact 2 characters, and region/city is capped to 36 characters respectively.

Document Revision History

Date Change Summary
August 04, 2021 Added details about 'ALL' flag