|
11 | 11 | MAX_IPV4_RANGE = 4294967295 |
12 | 12 | MAX_IPV6_RANGE = 340282366920938463463374607431768211455 |
13 | 13 |
|
14 | | -_COUNTRY_POSITION = (0, 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) |
15 | | -_REGION_POSITION = (0, 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) |
16 | | -_CITY_POSITION = (0, 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) |
17 | | -_LATITUDE_POSITION = (0, 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) |
18 | | -_LONGITUDE_POSITION = (0, 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) |
19 | | -_ZIPCODE_POSITION = (0, 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) |
20 | | -_TIMEZONE_POSITION = (0, 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) |
21 | | -_ISP_POSITION = (0, 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) |
22 | | -_DOMAIN_POSITION = (0, 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) |
23 | | -_NETSPEED_POSITION = (0, 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) |
24 | | -_IDDCODE_POSITION = (0, 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) |
25 | | -_AREACODE_POSITION = (0, 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) |
26 | | -_WEATHERSTATIONCODE_POSITION = (0, 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) |
27 | | -_WEATHERSTATIONNAME_POSITION = (0, 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) |
28 | | -_MCC_POSITION = (0, 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) |
29 | | -_MNC_POSITION = (0, 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) |
30 | | -_MOBILEBRAND_POSITION = (0, 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) |
31 | | -_ELEVATION_POSITION = (0, 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) |
32 | | -_USAGETYPE_POSITION = (0, 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) |
33 | | -_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, 0, 21) |
34 | | -_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, 0, 22) |
| 14 | +_COUNTRY_POSITION = (0, 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) |
| 15 | +_REGION_POSITION = (0, 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) |
| 16 | +_CITY_POSITION = (0, 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) |
| 17 | +_LATITUDE_POSITION = (0, 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) |
| 18 | +_LONGITUDE_POSITION = (0, 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) |
| 19 | +_ZIPCODE_POSITION = (0, 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) |
| 20 | +_TIMEZONE_POSITION = (0, 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) |
| 21 | +_ISP_POSITION = (0, 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) |
| 22 | +_DOMAIN_POSITION = (0, 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) |
| 23 | +_NETSPEED_POSITION = (0, 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) |
| 24 | +_IDDCODE_POSITION = (0, 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) |
| 25 | +_AREACODE_POSITION = (0, 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) |
| 26 | +_WEATHERSTATIONCODE_POSITION = (0, 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) |
| 27 | +_WEATHERSTATIONNAME_POSITION = (0, 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) |
| 28 | +_MCC_POSITION = (0, 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) |
| 29 | +_MNC_POSITION = (0, 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) |
| 30 | +_MOBILEBRAND_POSITION = (0, 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) |
| 31 | +_ELEVATION_POSITION = (0, 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) |
| 32 | +_USAGETYPE_POSITION = (0, 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) |
| 33 | +_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, 0, 21, 21) |
| 34 | +_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, 0, 22, 22) |
| 35 | +_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, 0, 23) |
| 36 | +_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, 0, 24) |
| 37 | +_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, 0, 25) |
35 | 38 |
|
36 | 39 | if sys.version < '3': |
37 | 40 | import urllib, httplib |
@@ -150,6 +153,9 @@ class IP2LocationRecord: |
150 | 153 | usage_type = "This parameter is unavailable in selected .BIN data file. Please upgrade data file." |
151 | 154 | address_type = "This parameter is unavailable in selected .BIN data file. Please upgrade data file." |
152 | 155 | category = "This parameter is unavailable in selected .BIN data file. Please upgrade data file." |
| 156 | + district = "This parameter is unavailable in selected .BIN data file. Please upgrade data file." |
| 157 | + asn = "This parameter is unavailable in selected .BIN data file. Please upgrade data file." |
| 158 | + as_name = "This parameter is unavailable in selected .BIN data file. Please upgrade data file." |
153 | 159 |
|
154 | 160 | def __str__(self): |
155 | 161 | return str(self.__dict__) |
@@ -317,6 +323,18 @@ def get_category(self, ip): |
317 | 323 | ''' Get category ''' |
318 | 324 | rec = self.get_all(ip) |
319 | 325 | return rec and rec.category |
| 326 | + def get_district(self, ip): |
| 327 | + ''' Get district ''' |
| 328 | + rec = self.get_all(ip) |
| 329 | + return rec and rec.district |
| 330 | + def get_asn(self, ip): |
| 331 | + ''' Get asn ''' |
| 332 | + rec = self.get_all(ip) |
| 333 | + return rec and rec.asn |
| 334 | + def get_as(self, ip): |
| 335 | + ''' Get as_name ''' |
| 336 | + rec = self.get_all(ip) |
| 337 | + return rec and rec.as_name |
320 | 338 |
|
321 | 339 | def get_all(self, addr): |
322 | 340 | ''' Get the whole record with all fields read from the file |
@@ -465,6 +483,15 @@ def calc_off(what, mid): |
465 | 483 | if _CATEGORY_POSITION[self._dbtype] != 0: |
466 | 484 | rec.category = self._reads(struct.unpack('<I', raw_positions_row[((_CATEGORY_POSITION[self._dbtype]-1) * 4 - 4) : ((_CATEGORY_POSITION[self._dbtype]-1) * 4)])[0] + 1) |
467 | 485 |
|
| 486 | + if _DISTRICT_POSITION[self._dbtype] != 0: |
| 487 | + rec.district = self._reads(struct.unpack('<I', raw_positions_row[((_DISTRICT_POSITION[self._dbtype]-1) * 4 - 4) : ((_DISTRICT_POSITION[self._dbtype]-1) * 4)])[0] + 1) |
| 488 | + |
| 489 | + if _ASN_POSITION[self._dbtype] != 0: |
| 490 | + rec.asn = self._reads(struct.unpack('<I', raw_positions_row[((_ASN_POSITION[self._dbtype]-1) * 4 - 4) : ((_ASN_POSITION[self._dbtype]-1) * 4)])[0] + 1) |
| 491 | + |
| 492 | + if _AS_POSITION[self._dbtype] != 0: |
| 493 | + rec.as_name = self._reads(struct.unpack('<I', raw_positions_row[((_AS_POSITION[self._dbtype]-1) * 4 - 4) : ((_AS_POSITION[self._dbtype]-1) * 4)])[0] + 1) |
| 494 | + |
468 | 495 | return rec |
469 | 496 |
|
470 | 497 | def __iter__(self): |
@@ -604,6 +631,9 @@ def _get_record(self, ip): |
604 | 631 | rec.usage_type = "INVALID IP ADDRESS" |
605 | 632 | rec.address_type = "INVALID IP ADDRESS" |
606 | 633 | rec.category = "INVALID IP ADDRESS" |
| 634 | + rec.district = "INVALID IP ADDRESS" |
| 635 | + rec.asn = "INVALID IP ADDRESS" |
| 636 | + rec.as_name = "INVALID IP ADDRESS" |
607 | 637 | return rec |
608 | 638 | else: |
609 | 639 | if ipv == 4: |
@@ -647,6 +677,9 @@ def _get_record(self, ip): |
647 | 677 | rec.usage_type = "IPV6 ADDRESS MISSING IN IPV4 BIN" |
648 | 678 | rec.address_type = "IPV6 ADDRESS MISSING IN IPV4 BIN" |
649 | 679 | rec.category = "IPV6 ADDRESS MISSING IN IPV4 BIN" |
| 680 | + rec.district = "IPV6 ADDRESS MISSING IN IPV4 BIN" |
| 681 | + rec.asn = "IPV6 ADDRESS MISSING IN IPV4 BIN" |
| 682 | + rec.as_name = "IPV6 ADDRESS MISSING IN IPV4 BIN" |
650 | 683 | return rec |
651 | 684 | # a, b = struct.unpack('!QQ', socket.inet_pton(socket.AF_INET6, ip)) |
652 | 685 | # ipno = (a << 64) | b |
|
0 commit comments