Class: Ip2proxy
- Inherits:
-
Object
- Object
- Ip2proxy
- Defined in:
- lib/ip2proxy_ruby.rb
Constant Summary collapse
- VERSION =
'1.0.3'- FIELD_NOT_SUPPORTED =
'NOT SUPPORTED'- INVALID_IP_ADDRESS =
'INVALID IP ADDRESS'
Instance Attribute Summary collapse
-
#base_addr ⇒ Object
Returns the value of attribute base_addr.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#count ⇒ Object
Returns the value of attribute count.
-
#database ⇒ Object
Returns the value of attribute database.
-
#databaseday ⇒ Object
Returns the value of attribute databaseday.
-
#databasemonth ⇒ Object
Returns the value of attribute databasemonth.
-
#databaseyear ⇒ Object
Returns the value of attribute databaseyear.
-
#db_index ⇒ Object
Returns the value of attribute db_index.
-
#file ⇒ Object
Returns the value of attribute file.
-
#ip_version ⇒ Object
Returns the value of attribute ip_version.
-
#ipno ⇒ Object
Returns the value of attribute ipno.
-
#ipv4databaseaddr ⇒ Object
Returns the value of attribute ipv4databaseaddr.
-
#ipv4databasecount ⇒ Object
Returns the value of attribute ipv4databasecount.
-
#ipv4indexbaseaddr ⇒ Object
Returns the value of attribute ipv4indexbaseaddr.
-
#ipv6databaseaddr ⇒ Object
Returns the value of attribute ipv6databaseaddr.
-
#ipv6databasecount ⇒ Object
Returns the value of attribute ipv6databasecount.
-
#ipv6indexbaseaddr ⇒ Object
Returns the value of attribute ipv6indexbaseaddr.
-
#record ⇒ Object
Returns the value of attribute record.
-
#record_class4 ⇒ Object
Returns the value of attribute record_class4.
-
#record_class6 ⇒ Object
Returns the value of attribute record_class6.
-
#v4 ⇒ Object
Returns the value of attribute v4.
Instance Method Summary collapse
- #close ⇒ Object
- #get_all(ip) ⇒ Object
- #get_city(ip) ⇒ Object
- #get_country_long(ip) ⇒ Object
- #get_country_short(ip) ⇒ Object
- #get_database_version ⇒ Object
- #get_isp(ip) ⇒ Object
- #get_module_version ⇒ Object
- #get_package_version ⇒ Object
- #get_proxytype(ip) ⇒ Object
- #get_region(ip) ⇒ Object
- #is_proxy(ip) ⇒ Object
- #open(url) ⇒ Object
Instance Attribute Details
#base_addr ⇒ Object
Returns the value of attribute base_addr.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def base_addr @base_addr end |
#columns ⇒ Object
Returns the value of attribute columns.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def columns @columns end |
#count ⇒ Object
Returns the value of attribute count.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def count @count end |
#database ⇒ Object
Returns the value of attribute database.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def database @database end |
#databaseday ⇒ Object
Returns the value of attribute databaseday.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def databaseday @databaseday end |
#databasemonth ⇒ Object
Returns the value of attribute databasemonth.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def databasemonth @databasemonth end |
#databaseyear ⇒ Object
Returns the value of attribute databaseyear.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def databaseyear @databaseyear end |
#db_index ⇒ Object
Returns the value of attribute db_index.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def db_index @db_index end |
#file ⇒ Object
Returns the value of attribute file.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def file @file end |
#ip_version ⇒ Object
Returns the value of attribute ip_version.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def ip_version @ip_version end |
#ipno ⇒ Object
Returns the value of attribute ipno.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def ipno @ipno end |
#ipv4databaseaddr ⇒ Object
Returns the value of attribute ipv4databaseaddr.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def ipv4databaseaddr @ipv4databaseaddr end |
#ipv4databasecount ⇒ Object
Returns the value of attribute ipv4databasecount.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def ipv4databasecount @ipv4databasecount end |
#ipv4indexbaseaddr ⇒ Object
Returns the value of attribute ipv4indexbaseaddr.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def ipv4indexbaseaddr @ipv4indexbaseaddr end |
#ipv6databaseaddr ⇒ Object
Returns the value of attribute ipv6databaseaddr.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def ipv6databaseaddr @ipv6databaseaddr end |
#ipv6databasecount ⇒ Object
Returns the value of attribute ipv6databasecount.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def ipv6databasecount @ipv6databasecount end |
#ipv6indexbaseaddr ⇒ Object
Returns the value of attribute ipv6indexbaseaddr.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def ipv6indexbaseaddr @ipv6indexbaseaddr end |
#record ⇒ Object
Returns the value of attribute record.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def record @record end |
#record_class4 ⇒ Object
Returns the value of attribute record_class4.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def record_class4 @record_class4 end |
#record_class6 ⇒ Object
Returns the value of attribute record_class6.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def record_class6 @record_class6 end |
#v4 ⇒ Object
Returns the value of attribute v4.
10 11 12 |
# File 'lib/ip2proxy_ruby.rb', line 10 def v4 @v4 end |
Instance Method Details
#close ⇒ Object
36 37 38 |
# File 'lib/ip2proxy_ruby.rb', line 36 def close() self.file.close end |
#get_all(ip) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/ip2proxy_ruby.rb', line 189 def get_all(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if !(rec.nil?) country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED city = (defined?(rec.city) && rec.city != '') ? rec.city : FIELD_NOT_SUPPORTED isp = (defined?(rec.isp) && rec.isp != '') ? rec.isp : FIELD_NOT_SUPPORTED proxytype = (defined?(rec.proxytype) && rec.proxytype != '') ? rec.proxytype : FIELD_NOT_SUPPORTED if self.db_index == 1 isproxy = (rec.country_short == '-') ? 0 : 1 else isproxy = (rec.proxytype == '-') ? 0 : (rec.proxytype == 'DCH') ? 2 : 1 end else country_short = INVALID_IP_ADDRESS country_long = INVALID_IP_ADDRESS region = INVALID_IP_ADDRESS city = INVALID_IP_ADDRESS isp = INVALID_IP_ADDRESS proxytype = INVALID_IP_ADDRESS isproxy = -1 end else country_short = INVALID_IP_ADDRESS country_long = INVALID_IP_ADDRESS region = INVALID_IP_ADDRESS city = INVALID_IP_ADDRESS isp = INVALID_IP_ADDRESS proxytype = INVALID_IP_ADDRESS isproxy = -1 end results = {} results['is_proxy'] = isproxy results['proxy_type'] = proxytype results['country_short'] = country_short results['country_long'] = country_long results['region'] = region results['city'] = city results['isp'] = isp return results end |
#get_city(ip) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/ip2proxy_ruby.rb', line 125 def get_city(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if !(rec.nil?) city = (defined?(rec.city) && rec.city != '') ? rec.city : FIELD_NOT_SUPPORTED else city = INVALID_IP_ADDRESS end else city = INVALID_IP_ADDRESS end return city end |
#get_country_long(ip) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ip2proxy_ruby.rb', line 95 def get_country_long(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if !(rec.nil?) country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED else country_long = INVALID_IP_ADDRESS end else country_long = INVALID_IP_ADDRESS end return country_long end |
#get_country_short(ip) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ip2proxy_ruby.rb', line 80 def get_country_short(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if !(rec.nil?) country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED else country_short = INVALID_IP_ADDRESS end else country_short = INVALID_IP_ADDRESS end return country_short end |
#get_database_version ⇒ Object
48 49 50 |
# File 'lib/ip2proxy_ruby.rb', line 48 def get_database_version() return (self.databaseyear).to_s + "." + (self.databasemonth).to_s + "." + (self.databaseday).to_s end |
#get_isp(ip) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/ip2proxy_ruby.rb', line 140 def get_isp(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if !(rec.nil?) isp = (defined?(rec.isp) && rec.isp != '') ? rec.isp : FIELD_NOT_SUPPORTED else isp = INVALID_IP_ADDRESS end else isp = INVALID_IP_ADDRESS end return isp end |
#get_module_version ⇒ Object
40 41 42 |
# File 'lib/ip2proxy_ruby.rb', line 40 def get_module_version() return VERSION end |
#get_package_version ⇒ Object
44 45 46 |
# File 'lib/ip2proxy_ruby.rb', line 44 def get_package_version() return (self.db_index).to_s end |
#get_proxytype(ip) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/ip2proxy_ruby.rb', line 155 def get_proxytype(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if !(rec.nil?) proxytype = (defined?(rec.proxytype) && rec.proxytype != '') ? rec.proxytype : FIELD_NOT_SUPPORTED else proxytype = INVALID_IP_ADDRESS end else proxytype = INVALID_IP_ADDRESS end return proxytype end |
#get_region(ip) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ip2proxy_ruby.rb', line 110 def get_region(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if !(rec.nil?) region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED else region = INVALID_IP_ADDRESS end else region = INVALID_IP_ADDRESS end return region end |
#is_proxy(ip) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/ip2proxy_ruby.rb', line 170 def is_proxy(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if !(rec.nil?) if self.db_index == 1 isproxy = (rec.country_short == '-') ? 0 : 1 else isproxy = (rec.proxytype == '-') ? 0 : (rec.proxytype == 'DCH') ? 2 : 1 end else isproxy = -1 end else isproxy = -1 end return isproxy end |
#open(url) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ip2proxy_ruby.rb', line 16 def open(url) self.file = File.open(File. url, 'rb') i2p = Ip2proxyConfig.read(file) self.db_index = i2p.databasetype self.columns = i2p.databasecolumn + 0 self.databaseyear = 2000 + i2p.databaseyear self.databasemonth = i2p.databasemonth self.databaseday = i2p.databaseday self.database = I2pDbConfig.setup_database(self.db_index) self.ipv4databasecount = i2p.ipv4databasecount self.ipv4databaseaddr = i2p.ipv4databaseaddr self.ipv6databasecount = i2p.ipv6databasecount self.ipv6databaseaddr = i2p.ipv6databaseaddr self.ipv4indexbaseaddr = i2p.ipv4indexbaseaddr self.ipv6indexbaseaddr = i2p.ipv6indexbaseaddr self.record_class4 = (Ip2ProxyRecord.init database, 4) self.record_class6 = (Ip2ProxyRecord.init database, 6) self end |