-
Notifications
You must be signed in to change notification settings - Fork 44
/
Sample.pas
77 lines (71 loc) · 1.38 KB
/
Sample.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
unit Sample;
interface
//http://www.maxmind.com/download/geoip/database/
function LookupCountry(IP: string): string;
//function LookupCity(IP: string): string;
//function LookupOrg(IP: string): string;
implementation
uses
Windows,
SysUtils,
GeoIP;
function LookupCountry(IP: string): string;
var
GeoIP: TGeoIP;
GeoIPCountry: TGeoIPCountry;
begin
GeoIP := TGeoIP.Create('GeoIP.dat');
try
if GeoIP.GetCountry(IP, GeoIPCountry) = GEOIP_SUCCESS then
begin
Result := GeoIPCountry.CountryCode + ' - ' + GeoIPCountry.CountryName;
end
else
begin
Result := 'ERROR - ERROR';
end;
finally
GeoIP.Free;
end;
end;
{
function LookupCity(IP: string): string;
var
GeoIP: TGeoIP;
GeoIPCity: TGeoIPCity;
begin
GeoIP := TGeoIP.Create('GeoIPCity.dat');
try
if GeoIP.GetCity(IP, GeoIPCity) = GEOIP_SUCCESS then
begin
Result := GeoIPCity.City + ', ' + GeoIPCity.Region + ', ' + GeoIPCity.CountryName;
end
else
begin
Result := 'ERROR';
end;
finally
GeoIP.Free;
end;
end;
function LookupOrg(IP: string): string;
var
GeoIP: TGeoIP;
GeoIPOrg: TGeoIPOrg;
begin
GeoIP := TGeoIP.Create('GeoIPOrg.dat');
try
if GeoIP.GetOrg(IP, GeoIPOrg) = GEOIP_SUCCESS then
begin
Result := GeoIPOrg.Name;
end
else
begin
Result := 'ERROR';
end;
finally
GeoIP.Free;
end;
end;
}
end.