Skip to content

Commit 4dca6da

Browse files
committed
Added new field "fraud_score" to support PX12 database.
1 parent 07fbd47 commit 4dca6da

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

ChangeLog

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
3.5.0 2025-02-18
2+
* Added new field "fraud_score" to support PX12 database.
3+
14
3.4.2 2024-10-04
25
* Tested with CPython and PyPy.
3-
6+
47
3.4.1 2024-09-27
58
* Tested with Python 3.12.
69

IP2Proxy.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def inet_pton(t, addr):
8585
return out_addr_p.raw
8686
socket.inet_pton = inet_pton
8787

88-
_VERSION = '3.3.0'
88+
_VERSION = '3.5.0'
8989
_NO_IP = 'MISSING IP ADDRESS'
9090
_FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
9191
_INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
@@ -108,25 +108,27 @@ class IP2ProxyRecord:
108108
domain = _FIELD_NOT_SUPPORTED
109109
threat = _FIELD_NOT_SUPPORTED
110110
provider = _FIELD_NOT_SUPPORTED
111+
fraud_score = _FIELD_NOT_SUPPORTED
111112

112113
def __str__(self):
113114
return str(self.__dict__)
114115

115116
def __repr__(self):
116117
return repr(self.__dict__)
117118

118-
_COUNTRY_POSITION = (0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)
119-
_REGION_POSITION = (0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4)
120-
_CITY_POSITION = (0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5)
121-
_ISP_POSITION = (0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6)
122-
_PROXYTYPE_POSITION = (0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
123-
_DOMAIN_POSITION = (0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7)
124-
_USAGETYPE_POSITION = (0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8)
125-
_ASN_POSITION = (0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9)
126-
_AS_POSITION = (0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10)
127-
_LASTSEEN_POSITION = (0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11)
128-
_THREAT_POSITION = (0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12)
129-
_PROVIDER_POSITION = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13)
119+
_COUNTRY_POSITION = (0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)
120+
_REGION_POSITION = (0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)
121+
_CITY_POSITION = (0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5)
122+
_ISP_POSITION = (0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6)
123+
_PROXYTYPE_POSITION = (0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
124+
_DOMAIN_POSITION = (0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7)
125+
_USAGETYPE_POSITION = (0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8)
126+
_ASN_POSITION = (0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9, 9)
127+
_AS_POSITION = (0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10)
128+
_LASTSEEN_POSITION = (0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11, 11)
129+
_THREAT_POSITION = (0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12, 12)
130+
_PROVIDER_POSITION = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 13)
131+
_FRAUD_SCORE_POSITION = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14)
130132

131133
class IP2Proxy(object):
132134
''' IP2Proxy database '''
@@ -324,6 +326,15 @@ def get_provider(self, ip):
324326
provider = _INVALID_IP_ADDRESS
325327
return provider
326328

329+
def get_fraud_score(self, ip):
330+
''' Get fraud_score'''
331+
try:
332+
rec = self._get_record(ip)
333+
fraud_score = rec.fraud_score
334+
except:
335+
fraud_score = _INVALID_IP_ADDRESS
336+
return fraud_score
337+
327338
def get_all(self, ip):
328339
''' Get the whole record with all fields read from the file '''
329340
try:
@@ -341,6 +352,7 @@ def get_all(self, ip):
341352
last_seen = rec.last_seen
342353
threat = rec.threat
343354
provider = rec.provider
355+
fraud_score = rec.fraud_score
344356
if rec.country_short != _INVALID_IP_ADDRESS:
345357
if self._dbtype == 1:
346358
is_proxy = 0 if (rec.country_short == '-') else ( 2 if ((rec.proxy_type == 'DCH') | (rec.proxy_type == 'SES')) else 1)
@@ -363,6 +375,7 @@ def get_all(self, ip):
363375
last_seen = _INVALID_IP_ADDRESS
364376
threat = _INVALID_IP_ADDRESS
365377
provider = _INVALID_IP_ADDRESS
378+
fraud_score = _INVALID_IP_ADDRESS
366379

367380
results = {}
368381
results['is_proxy'] = is_proxy
@@ -379,6 +392,7 @@ def get_all(self, ip):
379392
results['last_seen'] = last_seen
380393
results['threat'] = threat
381394
results['provider'] = provider
395+
results['fraud_score'] = fraud_score
382396
return results
383397

384398
def _reads(self, offset):
@@ -483,6 +497,11 @@ def calc_off(what, mid):
483497
elif _PROVIDER_POSITION[self._dbtype] == 0:
484498
rec.provider = _FIELD_NOT_SUPPORTED
485499

500+
if _FRAUD_SCORE_POSITION[self._dbtype] != 0:
501+
rec.fraud_score = self._reads(self._readi(calc_off(_FRAUD_SCORE_POSITION, mid)) + 1)
502+
elif _FRAUD_SCORE_POSITION[self._dbtype] == 0:
503+
rec.fraud_score = _FIELD_NOT_SUPPORTED
504+
486505
return rec
487506

488507
def __iter__(self):
@@ -592,6 +611,7 @@ def _get_record(self, ip):
592611
rec.last_seen = _INVALID_IP_ADDRESS
593612
rec.threat = _INVALID_IP_ADDRESS
594613
rec.provider = _INVALID_IP_ADDRESS
614+
rec.fraud_score = _INVALID_IP_ADDRESS
595615
return rec
596616
elif ipv == 4:
597617
# ipnum = struct.unpack('!L', socket.inet_pton(socket.AF_INET, ip))[0]
@@ -636,6 +656,7 @@ def _get_record(self, ip):
636656
rec.last_seen = _NO_IP
637657
rec.threat = _NO_IP
638658
rec.provider = _NO_IP
659+
rec.fraud_score = _NO_IP
639660
return rec
640661
else:
641662
rec = IP2ProxyRecord()
@@ -652,6 +673,7 @@ def _get_record(self, ip):
652673
rec.last_seen = _INVALID_IP_ADDRESS
653674
rec.threat = _INVALID_IP_ADDRESS
654675
rec.provider = _INVALID_IP_ADDRESS
676+
rec.fraud_score = _INVALID_IP_ADDRESS
655677
return rec
656678

657679
while low <= high:

LICENSE.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 - 2024 IP2Location.com
3+
Copyright (c) 2016 - 2025 IP2Location.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.0
22
Name: IP2Proxy
3-
Version: 3.4.2
3+
Version: 3.5.0
44
Summary: Python API for IP2Proxy database
55
Home-page: http://www.ip2location.com
66
Author: IP2Location

example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
print ('Last Seen: ' + db.get_last_seen("4.0.0.47"))
2626
print ('Threat: ' + db.get_threat("4.0.0.47"))
2727
print ('Provider: ' + db.get_provider("4.0.0.47"))
28+
print ('Fraud Score: ' + db.get_fraud_score("4.0.0.47"))
2829

2930
# single function to get all proxy data returned in array
3031
record = db.get_all("4.0.0.47")
@@ -43,6 +44,7 @@
4344
print ('Last Seen: ' + record['last_seen'])
4445
print ('Threat: ' + record['threat'])
4546
print ('Provider: ' + record['provider'])
47+
print ('Fraud Score: ' + record['fraud_score'])
4648

4749
# close IP2Proxy BIN database
4850
db.close()

0 commit comments

Comments
 (0)