Skip to content

Commit d827e7d

Browse files
committed
Added support for fraud score
1 parent 7f38241 commit d827e7d

File tree

13 files changed

+105
-74
lines changed

13 files changed

+105
-74
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2016 - 2024 IP2Location ( [email protected] )
1+
Copyright (c) 2016 - 2025 IP2Location ( [email protected] )
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

docs/source/code.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# IP2Proxy Ruby API
22

33
## Database Class
4-
```{py:function} open(database_file_path, file_mode)
4+
```{py:function} open(database_file_path)
55
Load the IP2Proxy BIN database.
66
77
:param str database_file_path: (Required) The file path links to IP2Location BIN databases.
8-
:param str file_mode: (Optional) Caching mode (one of FILE_IO, MEMORY_CACHE, or SHARED_MEMORY).
98
```
109

1110
```{py:function} get_package_version()
12-
Return the database's type, 1 to 10 respectively for PX1 to PX11. Please visit https://www.ip2location.com/databases/ip2proxy for details.
11+
Return the database's type, 1 to 12 respectively for PX1 to PX12. Please visit https://www.ip2location.com/databases/ip2proxy for details.
1312
1413
:return: Returns the package version.
1514
:rtype: string
@@ -40,17 +39,18 @@ Retrieve geolocation information for an IP address.
4039
4140
| Field Name | Description |
4241
| ---------------- | ------------------------------------------------------------ |
43-
| countryCode | Two-character country code based on ISO 3166. |
44-
| countryName | Country name based on ISO 3166. |
45-
| regionName | Region or state name. |
46-
| cityName | City name. |
47-
| isp | Internet Service Provider or company\'s name. |
48-
| domain | Internet domain name associated with IP address range. |
49-
| usageType | Usage type classification of ISP or company. |
50-
| asn | Autonomous system number (ASN). |
51-
| as | Autonomous system (AS) name. |
52-
| lastSeen | Proxy last seen in days. |
53-
| threat | Security threat reported. |
54-
| proxyType | Type of proxy. |
55-
| provider | Name of VPN provider if available. |
42+
| country_short | Two-character country code based on ISO 3166. |
43+
| country_long | Country name based on ISO 3166. |
44+
| region | Region or state name. |
45+
| city | City name. |
46+
| isp | Internet Service Provider or company\'s name. |
47+
| domain | Internet domain name associated with IP address range. |
48+
| usagetype | Usage type classification of ISP or company. |
49+
| asn | Autonomous system number (ASN). |
50+
| as | Autonomous system (AS) name. |
51+
| last_seen | Proxy last seen in days. |
52+
| threat | Security threat reported. |
53+
| is_proxy | Type of proxy. |
54+
| provider | Name of VPN provider if available. |
55+
| fraud_score | Potential risk score (0 - 99) associated with IP address. |
5656
```

docs/source/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Total Downloads](https://img.shields.io/gem/dt/ip2proxy_ruby.svg)](https://rubygems.org/gems/ip2proxy_ruby)
33

44
# IP2Proxy Ruby Library
5-
This module allows user to reverse search of IP address to detect VPN servers, open proxies, web proxies, Tor exit nodes, search engine robots, data center ranges, residential proxies, consumer privacy networks, and enterprise private networks using IP2Proxy BIN database. Other information available includes proxy type, country, state, city, ISP, domain name, usage type, AS number, AS name, threats, last seen date and provider names. It lookup the proxy IP address from **IP2Proxy BIN Data** file or web service.
5+
This module allows user to reverse search of IP address to detect VPN servers, open proxies, web proxies, Tor exit nodes, search engine robots, data center ranges, residential proxies, consumer privacy networks, and enterprise private networks using IP2Proxy BIN database. Other information available includes proxy type, country, state, city, ISP, domain name, usage type, AS number, AS name, threats, last seen date, provider names and potential risk score associated with IP address. It lookup the proxy IP address from **IP2Proxy BIN Data** file or web service.
66

77
For more details, please visit:
88
[https://www.ip2location.com/ip2proxy/developers/ruby](https://www.ip2location.com/ip2proxy/developers/ruby)

docs/source/quickstart.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can query the geolocation information from the IP2Proxy BIN database as belo
3030
require 'ip2proxy_ruby'
3131

3232
# open IP2Proxy BIN database for proxy lookup
33-
i2p = Ip2proxy.new.open("./data/PX11.SAMPLE.BIN")
33+
i2p = Ip2proxy.new.open("./data/PX12.SAMPLE.BIN")
3434

3535
# get versioning information
3636
print 'Module Version: ' + i2p.get_module_version + "\n"
@@ -52,6 +52,7 @@ print 'AS: ' + i2p.get_as('1.2.3.4') + "\n"
5252
print 'Last Seen: ' + i2p.get_last_seen('1.2.3.4') + "\n"
5353
print 'Threat: ' + i2p.get_threat('1.2.3.4') + "\n"
5454
print 'Provider: ' + i2p.get_provider('1.2.3.4') + "\n"
55+
print 'Fraud Score: ' + i2p.get_fraud_score('1.2.3.4') + "\n"
5556

5657
# single function to get all proxy data returned in array
5758
record = i2p.get_all('1.2.3.4')
@@ -69,6 +70,7 @@ print 'AS: ' + record['as'] + "\n"
6970
print 'Last Seen: ' + record['last_seen'] + "\n"
7071
print 'Threat: ' + record['threat'] + "\n"
7172
print 'Provider: ' + record['provider'] + "\n"
73+
print 'Fraud Score: ' + record['fraud_score'] + "\n"
7274

7375
# close IP2Proxy BIN database
7476
i2p.close()

example.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'ip2proxy_ruby'
22

33
# open IP2Proxy BIN database for proxy lookup
4-
i2p = Ip2proxy.new.open("./data/PX11.SAMPLE.BIN")
4+
i2p = Ip2proxy.new.open("./data/PX12.SAMPLE.BIN")
55

66
# get versioning information
77
print 'Module Version: ' + i2p.get_module_version + "\n"
@@ -23,6 +23,7 @@
2323
print 'Last Seen: ' + i2p.get_last_seen('1.2.3.4') + "\n"
2424
print 'Threat: ' + i2p.get_threat('1.2.3.4') + "\n"
2525
print 'Provider: ' + i2p.get_provider('1.2.3.4') + "\n"
26+
print 'Fraud Score: ' + i2p.get_fraud_score('1.2.3.4') + "\n"
2627

2728
# single function to get all proxy data returned in array
2829
record = i2p.get_all('1.2.3.4')
@@ -40,6 +41,7 @@
4041
print 'Last Seen: ' + record['last_seen'] + "\n"
4142
print 'Threat: ' + record['threat'] + "\n"
4243
print 'Provider: ' + record['provider'] + "\n"
44+
print 'Fraud Score: ' + record['fraud_score'] + "\n"
4345

4446
# close IP2Proxy BIN database
4547
i2p.close()

ip2proxy_ruby.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |s|
44
s.name = "ip2proxy_ruby"
5-
s.version = "3.3.1"
5+
s.version = "3.4.0"
66
s.authors = ["ip2location"]
77
s.email = ["[email protected]"]
88

@@ -31,15 +31,16 @@ Gem::Specification.new do |s|
3131
"lib/ip2proxy_ruby/i2p_string_data.rb",
3232
"lib/ip2proxy_ruby/ip2proxy_config.rb",
3333
"lib/ip2proxy_ruby/ip2proxy_record.rb",
34-
"spec/assets/PX11.SAMPLE.BIN",
34+
"spec/assets/PX12.SAMPLE.BIN",
3535
"spec/ip2proxy_ruby_database_spec.rb",
3636
"spec/spec_helper.rb",
37-
"rb/data/PX11.SAMPLE.BIN"
37+
"rb/data/PX12.SAMPLE.BIN"
3838
]
3939

4040
if s.respond_to?(:metadata=)
4141
s.metadata = {
4242
"bug_tracker_uri" => "https://github.com/ip2location/ip2proxy-ruby/issues",
43+
"documentation_uri" => "https://www.rubydoc.info/gems/ip2proxy_ruby",
4344
"homepage_uri" => "https://www.ip2location.com",
4445
"source_code_uri" => "https://github.com/ip2location/ip2proxy-ruby",
4546
}

lib/ip2proxy_ruby.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class Ip2proxy
1212
attr_accessor :record_class4, :record_class6, :v4, :file, :db_index, :count, :base_addr, :ipno, :record, :database, :columns, :ip_version, :ipv4databasecount, :ipv4databaseaddr, :ipv4indexbaseaddr, :ipv6databasecount, :ipv6databaseaddr, :ipv6indexbaseaddr, :databaseyear, :databasemonth, :databaseday, :last_err_msg
1313

14-
VERSION = '3.3.1'
14+
VERSION = '3.4.0'
1515
FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
1616
INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
1717
INVALID_BIN_DATABASE = 'Incorrect IP2Proxy BIN file format. Please make sure that you are using the latest IP2Proxy BIN file.'
@@ -322,6 +322,21 @@ def get_provider(ip)
322322
return provider
323323
end
324324

325+
def get_fraud_score(ip)
326+
valid = !(IPAddr.new(ip) rescue nil).nil?
327+
if valid
328+
rec = get_record(ip)
329+
if !(rec.nil?)
330+
fraud_score = (defined?(rec.fraud_score) && rec.fraud_score != '') ? rec.fraud_score : FIELD_NOT_SUPPORTED
331+
else
332+
fraud_score = INVALID_IP_ADDRESS
333+
end
334+
else
335+
fraud_score = INVALID_IP_ADDRESS
336+
end
337+
return fraud_score
338+
end
339+
325340
def get_all(ip)
326341
valid = !(IPAddr.new(ip) rescue nil).nil?
327342
if valid
@@ -340,6 +355,7 @@ def get_all(ip)
340355
last_seen = (defined?(rec.lastseen) && rec.lastseen != '') ? rec.lastseen : FIELD_NOT_SUPPORTED
341356
threat = (defined?(rec.threat) && rec.threat != '') ? rec.threat : FIELD_NOT_SUPPORTED
342357
provider = (defined?(rec.provider) && rec.provider != '') ? rec.provider : FIELD_NOT_SUPPORTED
358+
fraud_score = (defined?(rec.fraud_score) && rec.fraud_score != '') ? rec.fraud_score : FIELD_NOT_SUPPORTED
343359
if self.db_index == 1
344360
isproxy = (rec.country_short == '-') ? 0 : 1
345361
else
@@ -359,6 +375,7 @@ def get_all(ip)
359375
last_seen = INVALID_IP_ADDRESS
360376
threat = INVALID_IP_ADDRESS
361377
provider = INVALID_IP_ADDRESS
378+
fraud_score = INVALID_IP_ADDRESS
362379
isproxy = -1
363380
end
364381
else
@@ -375,6 +392,7 @@ def get_all(ip)
375392
last_seen = INVALID_IP_ADDRESS
376393
threat = INVALID_IP_ADDRESS
377394
provider = INVALID_IP_ADDRESS
395+
fraud_score = INVALID_IP_ADDRESS
378396
isproxy = -1
379397
end
380398
results = {}
@@ -392,6 +410,7 @@ def get_all(ip)
392410
results['last_seen'] = last_seen
393411
results['threat'] = threat
394412
results['provider'] = provider
413+
results['fraud_score'] = fraud_score
395414
return results
396415
end
397416

lib/ip2proxy_ruby/i2p_database_config.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
class I2pDbConfig
22
COLUMNS = {
3-
:COUNTRY => [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
4-
:REGION => [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4],
5-
:CITY => [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5],
6-
:ISP => [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6],
7-
:PROXYTYPE => [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
8-
:DOMAIN => [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7],
9-
:USAGETYPE => [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8],
10-
:ASN => [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9],
11-
:AS => [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10],
12-
:LASTSEEN => [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11],
13-
:THREAT => [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12],
14-
:PROVIDER => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13]
3+
:COUNTRY => [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
4+
:REGION => [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
5+
:CITY => [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
6+
:ISP => [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6],
7+
:PROXYTYPE => [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
8+
:DOMAIN => [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7],
9+
:USAGETYPE => [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8],
10+
:ASN => [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9, 9],
11+
:AS => [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10],
12+
:LASTSEEN => [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11, 11],
13+
:THREAT => [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12, 12],
14+
:PROVIDER => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 13],
15+
:FRAUD_SCORE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14]
1516
}
1617

1718
def self.setup_database(db_index)

rb/data/PX11.SAMPLE.BIN

-1 MB
Binary file not shown.

rb/data/PX12.SAMPLE.BIN

2.43 MB
Binary file not shown.

0 commit comments

Comments
 (0)