lib/ip2proxy_ruby.rb in ip2proxy_ruby-2.1.0 vs lib/ip2proxy_ruby.rb in ip2proxy_ruby-3.0.0
- old
+ new
@@ -7,11 +7,11 @@
require_relative 'ip2proxy_ruby/ip2proxy_record'
class Ip2proxy
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
- VERSION = '2.1.0'
+ VERSION = '3.0.0'
FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
def open(url)
self.file = File.open(File.expand_path url, 'rb')
@@ -245,10 +245,25 @@
last_seen = INVALID_IP_ADDRESS
end
return last_seen
end
+ def get_threat(ip)
+ valid = !(IPAddr.new(ip) rescue nil).nil?
+ if valid
+ rec = get_record(ip)
+ if !(rec.nil?)
+ threat = (defined?(rec.threat) && rec.threat != '') ? rec.threat : FIELD_NOT_SUPPORTED
+ else
+ threat = INVALID_IP_ADDRESS
+ end
+ else
+ threat = INVALID_IP_ADDRESS
+ end
+ return threat
+ end
+
def is_proxy(ip)
valid = !(IPAddr.new(ip) rescue nil).nil?
if valid
rec = get_record(ip)
if !(rec.nil?)
@@ -280,10 +295,11 @@
domain = (defined?(rec.domain) && rec.domain != '') ? rec.domain : FIELD_NOT_SUPPORTED
usagetype = (defined?(rec.usagetype) && rec.usagetype != '') ? rec.usagetype : FIELD_NOT_SUPPORTED
asn = (defined?(rec.asn) && rec.asn != '') ? rec.asn : FIELD_NOT_SUPPORTED
as = (defined?(rec.as) && rec.as != '') ? rec.as : FIELD_NOT_SUPPORTED
last_seen = (defined?(rec.lastseen) && rec.lastseen != '') ? rec.lastseen : FIELD_NOT_SUPPORTED
+ threat = (defined?(rec.threat) && rec.threat != '') ? rec.threat : FIELD_NOT_SUPPORTED
if self.db_index == 1
isproxy = (rec.country_short == '-') ? 0 : 1
else
isproxy = (rec.proxytype == '-') ? 0 : (rec.proxytype == 'DCH' || rec.proxytype == 'SES') ? 2 : 1
end
@@ -297,10 +313,11 @@
domain = INVALID_IP_ADDRESS
usagetype = INVALID_IP_ADDRESS
asn = INVALID_IP_ADDRESS
as = INVALID_IP_ADDRESS
last_seen = INVALID_IP_ADDRESS
+ threat = INVALID_IP_ADDRESS
isproxy = -1
end
else
country_short = INVALID_IP_ADDRESS
country_long = INVALID_IP_ADDRESS
@@ -311,10 +328,11 @@
domain = INVALID_IP_ADDRESS
usagetype = INVALID_IP_ADDRESS
asn = INVALID_IP_ADDRESS
as = INVALID_IP_ADDRESS
last_seen = INVALID_IP_ADDRESS
+ threat = INVALID_IP_ADDRESS
isproxy = -1
end
results = {}
results['is_proxy'] = isproxy
results['proxy_type'] = proxytype
@@ -326,9 +344,10 @@
results['domain'] = domain
results['usagetype'] = usagetype
results['asn'] = asn
results['as'] = as
results['last_seen'] = last_seen
+ results['threat'] = threat
return results
end
def bsearch(low, high, ipnum, base_addr, col_length)
while low <= high do
\ No newline at end of file