TsgcWebSocketFirewall › Methods › LookupCountry
Returns the ISO 3166-1 alpha-2 country code for an IP address, using the loaded GeoIP database or the OnResolveCountry event handler.
function LookupCountry(const aIP: string): string;
| Name | Type | Description |
|---|---|---|
aIP | const string | IPv4 or IPv6 address to resolve to a country. |
Two-letter country code in upper case (e.g. "US", "DE", "ES") or an empty string when the IP cannot be resolved. (string)
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.
var
vCountry: string;
begin
vCountry := sgcWebSocketFirewall1.LookupCountry(Connection.IP);
Log('client country: ' + vCountry);
end;