Skip to content

Commit 9787712

Browse files
Bug Fix: Allow for two simultanious readers.
1 parent 69e2c02 commit 9787712

3 files changed

Lines changed: 51 additions & 55 deletions

File tree

IPQualityScore/BinaryOption.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ def Create(value):
2121
IPV6MAP = 1 << 1
2222
BLACKLISTFILE = 1 << 2
2323
BINARYDATA = 1 << 7
24-
2524
TREEDATA = 1 << 2
2625
STRINGDATA = 1 << 3
2726
SMALLINTDATA = 1 << 4
2827
INTDATA = 1 << 5
2928
FLOATDATA = 1 << 6
30-
3129
ISPROXY = 1 << 0
3230
ISVPN = 1 << 1
3331
ISTOR = 1 << 2
@@ -36,7 +34,6 @@ def Create(value):
3634
RECENTABUSE = 1 << 5
3735
ISBLACKLISTED = 1 << 6
3836
ISPRIVATE = 1 << 7
39-
4037
ISMOBILE = 1 << 0
4138
HASOPENPORTS = 1 << 1
4239
ISHOSTINGPROVIDER = 1 << 2
@@ -45,12 +42,12 @@ def Create(value):
4542
PUBLICACCESSPOINT = 1 << 5
4643
RESERVEDONE = 1 << 6
4744
RESERVEDTWO = 1 << 7
48-
4945
RESERVEDTHREE = 1 << 0
5046
RESERVEDFOUR = 1 << 1
5147
RESERVEDFIVE = 1 << 2
5248
CONNECTIONTYPEONE = 1 << 3
5349
CONNECTIONTYPETWO = 1 << 4
5450
CONNECTIONTYPETHREE = 1 << 5
5551
ABUSEVELOCITYONE = 1 << 6
56-
ABUSEVELOCITYTWO = 1 << 7
52+
ABUSEVELOCITYTWO = 1 << 7
53+

IPQualityScore/DBReader.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import os
23
from binascii import hexlify
34
from socket import error, inet_aton, inet_pton, socket
@@ -21,13 +22,7 @@ class DBReader:
2122
COLUNN_HEADER = "<P23xB" #"x%s/a23name/Cvalue" null 23null-padded_string UnsigedChar <x23xB
2223
HEADERS = "<BB3BHL"
2324

24-
handler = None
25-
tree_start = None
26-
tree_end = None
27-
record_bytes = None
28-
columns = []
29-
ipv6 = False
30-
blacklistfile = False
25+
3126

3227
def __init__(self, filename:str):
3328
if not os.path.isfile(filename):
@@ -38,6 +33,13 @@ def __init__(self, filename:str):
3833
except IOError:
3934
raise FileReaderException('Invalid or non existant file name specified. Please check the file and try again')
4035

36+
self.tree_start = None
37+
self.tree_end = None
38+
self.record_bytes = None
39+
self.columns = []
40+
self.ipv6 = False
41+
self.blacklistfile = False
42+
4143
self.SetupHeaders()
4244
self.SetupColumns()
4345
self.SetupTreeHeaders()
@@ -63,7 +65,7 @@ def Fetch(self, ip:str):
6365
if len(v_literal) <= position:
6466
raise IPNotFoundException("Invalid or nonexistant IP address specified for lookup. (EID: 8)")
6567

66-
if v_literal[position] == "0":
68+
if v_literal[position] == 0:
6769
pos = self.ReadAt(file_position, self.TREE_BYTE_WIDTH)
6870
if len(pos) == 4:
6971
file_position = unpack("<L", pos)[0]
@@ -75,15 +77,11 @@ def Fetch(self, ip:str):
7577
if(self.blacklistfile == False):
7678
if(file_position == 0):
7779
for i in range(position):
78-
if(v_literal[position - i] == "1"):
79-
l = list(v_literal)
80-
l[position - i] = "0"
81-
v_literal = ''.join(l)
80+
if(v_literal[position - i] == 1):
81+
l[position - i] = 0
8282

8383
for n in range(position - i + 1, len(v_literal)):
84-
l = list(v_literal)
85-
l[n] = "1"
86-
v_literal = ''.join(l)
84+
l[n] = 1
8785

8886
position = position - i
8987
file_position = previous[position]
@@ -191,14 +189,13 @@ def SetupTreeHeaders(self):
191189
self.tree_end = tree['tree_bytes'] + self.tree_start
192190

193191
def IP2Literal(self,ip):
194-
result = ""
195-
if(self.ipv6):
192+
result = []
193+
if (self.ipv6):
196194
for block in self.Expand(ip).split(":"):
197-
result += bin(int(block,16))[2:]
195+
for x in bin(int(block, 16))[2:] : result.append((x))
198196
else:
199197
for block in ip.split("."):
200-
result += bin(int(block,10))[2:].zfill(8)
201-
198+
for x in bin(int(block, 10))[2:].zfill(8) : result.append(int(x))
202199
return result
203200

204201
def CreateRecord(self,raw):
@@ -233,6 +230,7 @@ def CreateRecord(self,raw):
233230
current_byte += 4
234231

235232
elif column.Name() == "Longitude":
233+
236234
value = unpack("<f", raw[current_byte:current_byte+4])[0]
237235
record.Longitude(float(value))
238236
current_byte += 4
@@ -287,4 +285,5 @@ def IsIPv6(self, ip:str):
287285
return False
288286

289287
def __del__(self):
290-
self.handler.close()
288+
if self.handler:
289+
self.handler.close()

IPQualityScore/IPQSRecord.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@
22
from IPQualityScore.Columns import Column
33

44
class IPQSRecord:
5-
__fraudscore = {}
6-
__Columns = []
7-
8-
__IsProxy = False
9-
__IsVPN = False
10-
__IsTOR = False
11-
__IsCrawler = False
12-
__IsBot = False
13-
__IsBlackListed = False
14-
__IsPrivate = False
15-
__IsMobile = False
16-
__RecentAbuse = False
17-
__HasOpenPorts = False
18-
__IsHostingProvider = False
19-
__ActiveVPN = False
20-
__ActiveTOR = False
21-
__PublicAccessPoint = False
22-
__ConnectionType = 0
23-
__AbuseVelocity = 0
24-
__fraudscore = {}
25-
__Country = ""
26-
__City = ""
27-
__Region = ""
28-
__ISP = ""
29-
__Organization = ""
30-
__Timezone = ""
31-
__Latitude = 0.0
32-
__Longitude = 0.0
33-
__ASN = 0
5+
def __init__(self):
6+
self.__fraudscore = {}
7+
self.__Columns = []
8+
self.__IsProxy = False
9+
self.__IsVPN = False
10+
self.__IsTOR = False
11+
self.__IsCrawler = False
12+
self.__IsBot = False
13+
self.__IsBlackListed = False
14+
self.__IsPrivate = False
15+
self.__IsMobile = False
16+
self.__RecentAbuse = False
17+
self.__HasOpenPorts = False
18+
self.__IsHostingProvider = False
19+
self.__ActiveVPN = False
20+
self.__ActiveTOR = False
21+
self.__PublicAccessPoint = False
22+
self.__ConnectionType = 0
23+
self.__AbuseVelocity = 0
24+
self.__fraudscore = {}
25+
self.__Country = ""
26+
self.__City = ""
27+
self.__Region = ""
28+
self.__ISP = ""
29+
self.__Organization = ""
30+
self.__Timezone = ""
31+
self.__Latitude = 0.0
32+
self.__Longitude = 0.0
33+
self.__ASN = 0
3434

3535
def IsProxy(self, value = None):
3636
if value != None:

0 commit comments

Comments
 (0)