TsgcWebSocketFirewallMethods › LookupCountry

LookupCountry Method

Returns the ISO 3166-1 alpha-2 country code for an IP address, using the loaded GeoIP database or the OnResolveCountry event handler.

Syntax

function LookupCountry(const aIP: string): string;

Parameters

NameTypeDescription
aIPconst stringIPv4 or IPv6 address to resolve to a country.

Return Value

Two-letter country code in upper case (e.g. "US", "DE", "ES") or an empty string when the IP cannot be resolved. (string)

Remarks

Resolution order: if OnResolveCountry is assigned it is invoked first and its value wins; otherwise the in-memory database populated by LoadGeoIPDatabase is consulted with a binary search over the IP ranges. Results are cached per IP for the lifetime of the firewall instance so repeated lookups are constant-time.

Example

var
  vCountry: string;
begin
  vCountry := sgcWebSocketFirewall1.LookupCountry(Connection.IP);
  Log('client country: ' + vCountry);
end;

Back to Methods