11 // //////////////////////////////////////////////
22// Unit : IP2Location.pas //
3- // Version : 8.1 .0 //
4- // Date : June 2021 //
3+ // Version : 8.2 .0 //
4+ // Date : April 2023 //
55// Translator: IP2Location //
66// Email : support@ip2location.com //
77// License : MIT //
@@ -14,33 +14,36 @@ interface
1414uses Windows,SysUtils,IP2Loc_DBInterface;
1515
1616const
17- API_VERSION = ' 8.1 .0' ;
17+ API_VERSION = ' 8.2 .0' ;
1818 MAX_IPV4_RANGE = 4294967295 ;
1919 MAX_IPV6_RANGE = ' 340282366920938463463374607431768211455' ;
2020 IPV4 = 0 ;
2121 IPV6 = 1 ;
22- _COUNTRYSHORT = $000001 ;
23- _COUNTRYLONG = $000002 ;
24- _REGION = $000004 ;
25- _CITY = $000008 ;
26- _ISP = $000010 ;
27- _LATITUDE = $000020 ;
28- _LONGITUDE = $000040 ;
29- _DOMAIN = $000080 ;
30- _ZIPCODE = $000100 ;
31- _TIMEZONE = $000200 ;
32- _NETSPEED = $000400 ;
33- _IDDCODE = $000800 ;
34- _AREACODE = $001000 ;
35- _WEATHERSTATIONCODE = $002000 ;
36- _WEATHERSTATIONNAME = $004000 ;
37- _MCC = $008000 ;
38- _MNC = $010000 ;
39- _MOBILEBRAND = $020000 ;
40- _ELEVATION = $040000 ;
41- _USAGETYPE = $080000 ;
42- _ADDRESSTYPE = $100000 ;
43- _CATEGORY = $200000 ;
22+ _COUNTRYSHORT = $0000001 ;
23+ _COUNTRYLONG = $0000002 ;
24+ _REGION = $0000004 ;
25+ _CITY = $0000008 ;
26+ _ISP = $0000010 ;
27+ _LATITUDE = $0000020 ;
28+ _LONGITUDE = $0000040 ;
29+ _DOMAIN = $0000080 ;
30+ _ZIPCODE = $0000100 ;
31+ _TIMEZONE = $0000200 ;
32+ _NETSPEED = $0000400 ;
33+ _IDDCODE = $0000800 ;
34+ _AREACODE = $0001000 ;
35+ _WEATHERSTATIONCODE = $0002000 ;
36+ _WEATHERSTATIONNAME = $0004000 ;
37+ _MCC = $0008000 ;
38+ _MNC = $0010000 ;
39+ _MOBILEBRAND = $0020000 ;
40+ _ELEVATION = $0040000 ;
41+ _USAGETYPE = $0080000 ;
42+ _ADDRESSTYPE = $0100000 ;
43+ _CATEGORY = $0200000 ;
44+ _DISTRICT = $0400000 ;
45+ _ASN = $0800000 ;
46+ _AS = $1000000 ;
4447 _ALL = _COUNTRYSHORT or
4548 _COUNTRYLONG or
4649 _REGION or
@@ -62,7 +65,10 @@ interface
6265 _ELEVATION or
6366 _USAGETYPE or
6467 _ADDRESSTYPE or
65- _CATEGORY;
68+ _CATEGORY or
69+ _DISTRICT or
70+ _ASN or
71+ _AS;
6672 DEFAULT = $0001 ;
6773 NO_EMPTY_STRING = $0002 ;
6874 NO_LEADING = $0004 ;
@@ -121,6 +127,9 @@ _IP2LocationRecord = record
121127 usagetype:PChar;
122128 addresstype:PChar;
123129 category:PChar;
130+ district:PChar;
131+ asn:PChar;
132+ asname:PChar;
124133 end ;
125134 TIP2LocationRecord = _IP2LocationRecord;
126135
@@ -151,6 +160,9 @@ function IP2Location_get_country_elevation(loc:TIP2Location;ip:PChar):TIP2Locat
151160function IP2Location_get_country_usagetype (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
152161function IP2Location_get_country_addresstype (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
153162function IP2Location_get_country_category (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
163+ function IP2Location_get_country_district (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
164+ function IP2Location_get_country_asn (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
165+ function IP2Location_get_country_asname (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
154166function IP2Location_get_country_all (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
155167
156168implementation
@@ -159,27 +171,30 @@ implementation
159171
160172const
161173
162- COUNTRY_POSITION :array [0 ..25 ] of byte =(0 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 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addr := IP2Location_read32(loc.filehandle, 22 );
234249 loc.ipv6indexbaseaddr := IP2Location_read32(loc.filehandle, 26 );
235- loc.productcode := IP2Location_read32 (loc.filehandle, 30 );
236- loc.licensecode := IP2Location_read32 (loc.filehandle, 31 );
250+ loc.productcode := IP2Location_read8 (loc.filehandle, 30 );
251+ loc.licensecode := IP2Location_read8 (loc.filehandle, 31 );
237252 loc.databasesize := IP2Location_read32(loc.filehandle, 32 );
238253 result:=0 ;
239254end ;
@@ -375,6 +390,9 @@ function bad_record(const aMessage:PChar):TIP2LocationRecord;
375390result.usagetype:=aMessage;
376391result.addresstype:=aMessage;
377392result.category:=aMessage;
393+ result.district:=aMessage;
394+ result.asn:=aMessage;
395+ result.asname:=aMessage;
378396end ;
379397
380398function IP2Location_get_record (loc:TIP2Location;ipstring:PChar;mode:Cardinal):TIP2LocationRecord;
@@ -641,6 +659,24 @@ function read_record(loc:TIP2Location;rowaddr,mode:cardinal):TIP2LocationRecord;
641659 result.category := IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (CATEGORY_POSITION[dbtype]-1 )))
642660else
643661 result.category := NOT_SUPPORTED;
662+
663+
664+ if ((mode and _DISTRICT>0 ) and (DISTRICT_POSITION[dbtype] <> 0 )) then
665+ result.district := IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (DISTRICT_POSITION[dbtype]-1 )))
666+ else
667+ result.district := NOT_SUPPORTED;
668+
669+
670+ if ((mode and _ASN>0 ) and (ASN_POSITION[dbtype] <> 0 )) then
671+ result.asn := IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ASN_POSITION[dbtype]-1 )))
672+ else
673+ result.asn := NOT_SUPPORTED;
674+
675+
676+ if ((mode and _AS>0 ) and (AS_POSITION[dbtype] <> 0 )) then
677+ result.asname := IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (AS_POSITION[dbtype]-1 )))
678+ else
679+ result.asname := NOT_SUPPORTED;
644680end ;
645681
646682// Description: Open the IP2Location database file
@@ -834,6 +870,24 @@ function IP2Location_get_country_category(loc:TIP2Location;ip:PChar):TIP2Locatio
834870result:=IP2Location_get_record(loc,ip,_CATEGORY);
835871end ;
836872
873+ // Description: Get district
874+ function IP2Location_get_country_district (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
875+ begin
876+ result:=IP2Location_get_record(loc,ip,_DISTRICT);
877+ end ;
878+
879+ // Description: Get asn
880+ function IP2Location_get_country_asn (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
881+ begin
882+ result:=IP2Location_get_record(loc,ip,_ASN);
883+ end ;
884+
885+ // Description: Get as
886+ function IP2Location_get_country_asname (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
887+ begin
888+ result:=IP2Location_get_record(loc,ip,_AS);
889+ end ;
890+
837891// Description: Get all records
838892function IP2Location_get_country_all (loc:TIP2Location;ip:PChar):TIP2LocationRecord;
839893begin
0 commit comments