MyChat Scripts Engine: GeoIPGetFullInfoAsJSON, get full information about a user geographical location by his IP address
"For developers", "Server scripts", "Functions description", "GeoIP", "GeoIPGetFullInfoAsJSON".
Getting full information about a user by his IP address as a JSON object. This function uses local database and does not need the Internet connection.
Syntax
function GeoIPGetFullInfoAsJSON(sIP: string): string;
Parameters and return values
Parameter |
Type |
Value |
sIP |
string |
user IP address. |
Function result
Empty JSON object, If IP address is invalid or nothing is found. Otherwise, the function returns a JSON object that can be processed by the JSONGetString function:
{
"LocaleCode" : "en",
"ContinentCode" : "Europe",
"CountryISOCode" : "GR",
"CountryName" : "Greece",
"SubDivision1ISOCode" : "J",
"SubDivision1Name" : "",
"SubDivision1ISOCode" : "12",
"SubDivision2Name" : "Arcadia",
"CityName" : "Tripoli",
"MetroCode" : "",
"TimeZone" : "Europe/Athens"
}
Example
const
IP = '94.45.98.236';
FIELDS = 'LocaleCode,ContinentCode,ContinentName,CountryISOCode,CountryName,SubDivision1ISOCode,' +
'SubDivision1Name,SubDivision1ISOCode,SubDivision2Name,CityName,MetroCode,TimeZone';
var
sSmallInfo, sFullInfo, s, sFieldName, sData: string;
begin
sSmallInfo := GeoIPGetQuickInfo(IP);
sFullInfo := GeoIPGetFullInfoAsJSON(IP);
mLogScript('IP address: ' + IP, '');
if length(sSmallInfo) > 0 then begin
mLogScript('Quick info: ' + sSmallInfo, '');
mLogScript('Full info:', '');
s := FIELDS;
while length(s) > 0 do begin
sFieldName := Fetch(s, ',');
if JSONGetString(sFullInfo, sFieldName, sData) = 0 then
if length(sData) > 0 then
mLogScript(sData, sFieldName);
end;
end else mLogScript('No information', '');
end.
Script work result
[17:25:48] (Log "GEOIP"): IP address: 94.45.98.236
[17:25:48] (Log "GEOIP"): Quick info: Ukraine|Fastiv
[17:25:48] (Log "GEOIP"): Full info:
[17:25:48] (Log "GEOIP"): [LocaleCode] en
[17:25:48] (Log "GEOIP"): [ContinentCode] EU
[17:25:48] (Log "GEOIP"): [ContinentName] Europe
[17:25:48] (Log "GEOIP"): [CountryISOCode] UA
[17:25:48] (Log "GEOIP"): [CountryName] Ukraine
[17:25:48] (Log "GEOIP"): [SubDivision1Name] Kiev region
[17:25:48] (Log "GEOIP"): [CityName] Fastiv
[17:25:48] (Log "GEOIP"): [TimeZone] Europe/Kiev
[17:25:48] (Run "GEOIP"): Script operation time: 17 ms
[17:25:48] (Run "GEOIP"): Script done successfully.