@@ -41,6 +41,9 @@ ip2location = {
4141 usagetype_position_offset = 0 ,
4242 addresstype_position_offset = 0 ,
4343 category_position_offset = 0 ,
44+ district_position_offset = 0 ,
45+ asn_position_offset = 0 ,
46+ as_position_offset = 0 ,
4447 country_enabled = false ,
4548 region_enabled = false ,
4649 city_enabled = false ,
@@ -61,7 +64,10 @@ ip2location = {
6164 elevation_enabled = false ,
6265 usagetype_enabled = false ,
6366 addresstype_enabled = false ,
64- category_enabled = false
67+ category_enabled = false ,
68+ district_enabled = false ,
69+ asn_enabled = false ,
70+ as_enabled = false
6571}
6672ip2location .__index = ip2location
6773
@@ -87,7 +93,10 @@ ip2locationrecord = {
8793 elevation = 0 ,
8894 usagetype = ' ' ,
8995 addresstype = ' ' ,
90- category = ' '
96+ category = ' ' ,
97+ district = ' ' ,
98+ asn = ' ' ,
99+ as = ' '
91100}
92101ip2locationrecord .__index = ip2locationrecord
93102
@@ -100,56 +109,62 @@ local to_6to4 = bn("42550872755692912415807417417958686719")
100109local from_teredo = bn (" 42540488161975842760550356425300246528" )
101110local to_teredo = bn (" 42540488241204005274814694018844196863" )
102111
103- local country_position = {2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 }
104- local region_position = {0 , 0 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 }
105- local city_position = {0 , 0 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 }
106- local isp_position = {0 , 3 , 0 , 5 , 0 , 7 , 5 , 7 , 0 , 8 , 0 , 9 , 0 , 9 , 0 , 9 , 0 , 9 , 7 , 9 , 0 , 9 , 7 , 9 , 9 }
107- local latitude_position = {0 , 0 , 0 , 0 , 5 , 5 , 0 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 }
108- local longitude_position = {0 , 0 , 0 , 0 , 6 , 6 , 0 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 }
109- local domain_position = {0 , 0 , 0 , 0 , 0 , 0 , 6 , 8 , 0 , 9 , 0 , 10 ,0 , 10 , 0 , 10 , 0 , 10 , 8 , 10 , 0 , 10 , 8 , 10 , 10 }
110- local zipcode_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 7 , 7 , 7 , 0 , 7 , 7 , 7 , 0 , 7 , 0 , 7 , 7 , 7 , 0 , 7 , 7 }
111- local timezone_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 8 , 8 , 7 , 8 , 8 , 8 , 7 , 8 , 0 , 8 , 8 , 8 , 0 , 8 , 8 }
112- local netspeed_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 8 , 11 ,0 , 11 ,8 , 11 , 0 , 11 , 0 , 11 , 0 , 11 , 11 }
113- local iddcode_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 9 , 12 , 0 , 12 , 0 , 12 , 9 , 12 , 0 , 12 , 12 }
114- local areacode_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 ,13 ,0 , 13 , 0 , 13 , 10 , 13 , 0 , 13 , 13 }
115- local weatherstationcode_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 9 , 14 , 0 , 14 , 0 , 14 , 0 , 14 , 14 }
116- local weatherstationname_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 15 , 0 , 15 , 0 , 15 , 0 , 15 , 15 }
117- local mcc_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 9 , 16 , 0 , 16 , 9 , 16 , 16 }
118- local mnc_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 ,17 , 0 , 17 , 10 , 17 , 17 }
119- local mobilebrand_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 11 ,18 , 0 , 18 , 11 , 18 , 18 }
120- local elevation_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 11 , 19 , 0 , 19 , 19 }
121- local usagetype_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 12 , 20 , 20 }
122- local addresstype_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 21 }
123- local category_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 22 }
124-
125- local api_version = " 8.6.1"
112+ local country_position = {2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 }
113+ local region_position = {0 , 0 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 }
114+ local city_position = {0 , 0 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 }
115+ local isp_position = {0 , 3 , 0 , 5 , 0 , 7 , 5 , 7 , 0 , 8 , 0 , 9 , 0 , 9 , 0 , 9 , 0 , 9 , 7 , 9 , 0 , 9 , 7 , 9 , 9 , 9 }
116+ local latitude_position = {0 , 0 , 0 , 0 , 5 , 5 , 0 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 }
117+ local longitude_position = {0 , 0 , 0 , 0 , 6 , 6 , 0 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 }
118+ local domain_position = {0 , 0 , 0 , 0 , 0 , 0 , 6 , 8 , 0 , 9 , 0 , 10 ,0 , 10 , 0 , 10 , 0 , 10 , 8 , 10 , 0 , 10 , 8 , 10 , 10 , 10 }
119+ local zipcode_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 7 , 7 , 7 , 0 , 7 , 7 , 7 , 0 , 7 , 0 , 7 , 7 , 7 , 0 , 7 , 7 , 7 }
120+ local timezone_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 8 , 8 , 7 , 8 , 8 , 8 , 7 , 8 , 0 , 8 , 8 , 8 , 0 , 8 , 8 , 8 }
121+ local netspeed_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 8 , 11 ,0 , 11 ,8 , 11 , 0 , 11 , 0 , 11 , 0 , 11 , 11 , 11 }
122+ local iddcode_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 9 , 12 , 0 , 12 , 0 , 12 , 9 , 12 , 0 , 12 , 12 , 12 }
123+ local areacode_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 ,13 ,0 , 13 , 0 , 13 , 10 , 13 , 0 , 13 , 13 , 13 }
124+ local weatherstationcode_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 9 , 14 , 0 , 14 , 0 , 14 , 0 , 14 , 14 , 14 }
125+ local weatherstationname_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 15 , 0 , 15 , 0 , 15 , 0 , 15 , 15 , 15 }
126+ local mcc_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 9 , 16 , 0 , 16 , 9 , 16 , 16 , 16 }
127+ local mnc_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 ,17 , 0 , 17 , 10 , 17 , 17 , 17 }
128+ local mobilebrand_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 11 ,18 , 0 , 18 , 11 , 18 , 18 , 18 }
129+ local elevation_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 11 , 19 , 0 , 19 , 19 , 19 }
130+ local usagetype_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 12 , 20 , 20 , 20 }
131+ local addresstype_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 21 , 21 }
132+ local category_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 22 , 22 }
133+ local district_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 23 }
134+ local asn_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 24 }
135+ local as_position = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 25 }
136+
137+ local api_version = " 8.7.0"
126138
127139local modes = {
128- countryshort = 0x000001 ,
129- countrylong = 0x000002 ,
130- region = 0x000004 ,
131- city = 0x000008 ,
132- isp = 0x000010 ,
133- latitude = 0x000020 ,
134- longitude = 0x000040 ,
135- domain = 0x000080 ,
136- zipcode = 0x000100 ,
137- timezone = 0x000200 ,
138- netspeed = 0x000400 ,
139- iddcode = 0x000800 ,
140- areacode = 0x001000 ,
141- weatherstationcode = 0x002000 ,
142- weatherstationname = 0x004000 ,
143- mcc = 0x008000 ,
144- mnc = 0x010000 ,
145- mobilebrand = 0x020000 ,
146- elevation = 0x040000 ,
147- usagetype = 0x080000 ,
148- addresstype = 0x100000 ,
149- category = 0x200000
140+ countryshort = 0x0000001 ,
141+ countrylong = 0x0000002 ,
142+ region = 0x0000004 ,
143+ city = 0x0000008 ,
144+ isp = 0x0000010 ,
145+ latitude = 0x0000020 ,
146+ longitude = 0x0000040 ,
147+ domain = 0x0000080 ,
148+ zipcode = 0x0000100 ,
149+ timezone = 0x0000200 ,
150+ netspeed = 0x0000400 ,
151+ iddcode = 0x0000800 ,
152+ areacode = 0x0001000 ,
153+ weatherstationcode = 0x0002000 ,
154+ weatherstationname = 0x0004000 ,
155+ mcc = 0x0008000 ,
156+ mnc = 0x0010000 ,
157+ mobilebrand = 0x0020000 ,
158+ elevation = 0x0040000 ,
159+ usagetype = 0x0080000 ,
160+ addresstype = 0x0100000 ,
161+ category = 0x0200000 ,
162+ district = 0x0400000 ,
163+ asn = 0x0800000 ,
164+ as = 0x1000000
150165}
151166
152- modes .all = modes .countryshort | modes .countrylong | modes .region | modes .city | modes .isp | modes .latitude | modes .longitude | modes .domain | modes .zipcode | modes .timezone | modes .netspeed | modes .iddcode | modes .areacode | modes .weatherstationcode | modes .weatherstationname | modes .mcc | modes .mnc | modes .mobilebrand | modes .elevation | modes .usagetype | modes .addresstype | modes .category
167+ modes .all = modes .countryshort | modes .countrylong | modes .region | modes .city | modes .isp | modes .latitude | modes .longitude | modes .domain | modes .zipcode | modes .timezone | modes .netspeed | modes .iddcode | modes .areacode | modes .weatherstationcode | modes .weatherstationname | modes .mcc | modes .mnc | modes .mobilebrand | modes .elevation | modes .usagetype | modes .addresstype | modes .category | modes . district | modes . asn | modes . as
153168
154169local invalid_address = " Invalid IP address."
155170local missing_file = " Invalid database file."
@@ -409,6 +424,18 @@ function ip2location:new(dbpath)
409424 x .category_position_offset = (category_position [dbt ] - 2 ) * 4
410425 x .category_enabled = true
411426 end
427+ if district_position [dbt ] ~= 0 then
428+ x .district_position_offset = (district_position [dbt ] - 2 ) * 4
429+ x .district_enabled = true
430+ end
431+ if asn_position [dbt ] ~= 0 then
432+ x .asn_position_offset = (asn_position [dbt ] - 2 ) * 4
433+ x .asn_enabled = true
434+ end
435+ if as_position [dbt ] ~= 0 then
436+ x .as_position_offset = (as_position [dbt ] - 2 ) * 4
437+ x .as_enabled = true
438+ end
412439
413440 x .metaok = true
414441 -- printme(x)
@@ -564,6 +591,9 @@ function ip2locationrecord:loadmessage(mesg)
564591 x .usagetype = mesg
565592 x .addresstype = mesg
566593 x .category = mesg
594+ x .district = mesg
595+ x .asn = mesg
596+ x .as = mesg
567597 return x
568598end
569599
@@ -740,10 +770,22 @@ function ip2location:query(ipaddress, mode)
740770 if (mode &modes .addresstype ~= 0 ) and (self .addresstype_enabled == true ) then
741771 result .addresstype = readstr (readuint32row (self .addresstype_position_offset , row ):asnumber (), self .f )
742772 end
773+
743774 if (mode &modes .category ~= 0 ) and (self .category_enabled == true ) then
744775 result .category = readstr (readuint32row (self .category_position_offset , row ):asnumber (), self .f )
745776 end
746777
778+ if (mode &modes .district ~= 0 ) and (self .district_enabled == true ) then
779+ result .district = readstr (readuint32row (self .district_position_offset , row ):asnumber (), self .f )
780+ end
781+
782+ if (mode &modes .asn ~= 0 ) and (self .asn_enabled == true ) then
783+ result .asn = readstr (readuint32row (self .asn_position_offset , row ):asnumber (), self .f )
784+ end
785+
786+ if (mode &modes .as ~= 0 ) and (self .as_enabled == true ) then
787+ result .as = readstr (readuint32row (self .as_position_offset , row ):asnumber (), self .f )
788+ end
747789 -- printme(result)
748790
749791 -- Lua style where you must have "return" as the last statement in a block
@@ -878,4 +920,19 @@ function ip2location:get_category(ipaddress)
878920 return self :query (ipaddress , modes .category )
879921end
880922
923+ -- get district
924+ function ip2location :get_district (ipaddress )
925+ return self :query (ipaddress , modes .district )
926+ end
927+
928+ -- get autonomous system number (ASN)
929+ function ip2location :get_asn (ipaddress )
930+ return self :query (ipaddress , modes .asn )
931+ end
932+
933+ -- get autonomous system (AS)
934+ function ip2location :get_as (ipaddress )
935+ return self :query (ipaddress , modes .as )
936+ end
937+
881938return ip2location
0 commit comments