DataScript *avi.utils.get_geo_from_ip*

Overview

This article discusses usage of the DataScript function avi.utils.get_geo_from_ip.
The avi.utils.get_geo_from_ip DataScript is used to extract geolocation database information.
Geolocation databased is used to determine the origin of a request or a client. The database is maintained on Avi Controllers. Avi Controller incorporates updates when there is an upgrade. 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.

DataScript

Function avi.utils.get_geo_from_ip
Description This DataScript is used to get 2-character country code associated with provided IP address
Parameter string is the IP address for which geodatabase information (country code) is queried for.
Returns ISO 3166-1 alpha-2 country code associated with that IP.
Nil if IPv6, internal, or invalid address is provided.
Example

   c_code = avi.utils.get_geo_from_ip( avi.vs.client_ip() )
   if (c_code == "CN" or c_code == "NG") then
      avi.http.add_header("Country", c_code)
   end