DataScript - avi.utils.get_geo_from_ip

Overview

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.

Notes:

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

  • The VSDataScriptSet that contains the DataScript using this function must refer to Geolocation Database.

  • The VSDataScriptSet that contains the DataScript using this function must refer to Geolocation Database.

DataScript

Functions avi.utils.get_geo_from_ip(ip_string, [ flag ] )
avi.utils.get_geo_from_ip(ip_string,"COUNTRY")
avi.utils.get_geo_from_ip(ip_string,"ASN")
avi.utils.get_geo_from_ip(ip_string,"LOCATION")
avi.utils.get_geo_from_ip(ip_string,"ALL")
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_CODE“] = “US“,
      [“ATTRIBUTE_COUNTRY_NAME“] = “United States“,
      [“ATTRIBUTE_CONTINENT_NAME“] = “North America“,
      [“ATTRIBUTE_CONTINENT_CODE“] = “NA“,
      [“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