Class: Ip2location
- Inherits:
-
Object
- Object
- Ip2location
- Defined in:
- lib/ip2location_ruby.rb
Constant Summary collapse
- VERSION =
'8.7.3'
- FIELD_NOT_SUPPORTED =
'NOT SUPPORTED'
- INVALID_IP_ADDRESS =
'INVALID IP ADDRESS'
- INVALID_BIN_DATABASE =
'Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file.'
- IPV6_ADDRESS_IN_IPV4_BIN =
'IPV6 ADDRESS MISSING IN IPV4 BIN'
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.
-
#last_err_msg ⇒ Object
Returns the value of attribute last_err_msg.
-
#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_addresstype(ip) ⇒ Object
- #get_all(ip) ⇒ Object
- #get_areacode(ip) ⇒ Object
- #get_as(ip) ⇒ Object
- #get_asn(ip) ⇒ Object
- #get_category(ip) ⇒ Object
- #get_city(ip) ⇒ Object
- #get_country_long(ip) ⇒ Object
- #get_country_short(ip) ⇒ Object
- #get_database_version ⇒ Object
- #get_district(ip) ⇒ Object
- #get_domain(ip) ⇒ Object
- #get_elevation(ip) ⇒ Object
- #get_iddcode(ip) ⇒ Object
- #get_isp(ip) ⇒ Object
- #get_last_error_message ⇒ Object
- #get_latitude(ip) ⇒ Object
- #get_longitude(ip) ⇒ Object
- #get_mcc(ip) ⇒ Object
- #get_mnc(ip) ⇒ Object
- #get_mobilebrand(ip) ⇒ Object
- #get_module_version ⇒ Object
- #get_netspeed(ip) ⇒ Object
- #get_package_version ⇒ Object
- #get_region(ip) ⇒ Object
- #get_timezone(ip) ⇒ Object
- #get_usagetype(ip) ⇒ Object
- #get_weatherstationcode(ip) ⇒ Object
- #get_weatherstationname(ip) ⇒ Object
- #get_zipcode(ip) ⇒ Object
- #open(url) ⇒ Object
- #validateip(ip) ⇒ Object
Instance Attribute Details
#base_addr ⇒ Object
Returns the value of attribute base_addr.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def base_addr @base_addr end |
#columns ⇒ Object
Returns the value of attribute columns.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def columns @columns end |
#count ⇒ Object
Returns the value of attribute count.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def count @count end |
#database ⇒ Object
Returns the value of attribute database.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def database @database end |
#databaseday ⇒ Object
Returns the value of attribute databaseday.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def databaseday @databaseday end |
#databasemonth ⇒ Object
Returns the value of attribute databasemonth.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def databasemonth @databasemonth end |
#databaseyear ⇒ Object
Returns the value of attribute databaseyear.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def databaseyear @databaseyear end |
#db_index ⇒ Object
Returns the value of attribute db_index.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def db_index @db_index end |
#file ⇒ Object
Returns the value of attribute file.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def file @file end |
#ip_version ⇒ Object
Returns the value of attribute ip_version.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def ip_version @ip_version end |
#ipno ⇒ Object
Returns the value of attribute ipno.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def ipno @ipno end |
#ipv4databaseaddr ⇒ Object
Returns the value of attribute ipv4databaseaddr.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def ipv4databaseaddr @ipv4databaseaddr end |
#ipv4databasecount ⇒ Object
Returns the value of attribute ipv4databasecount.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def ipv4databasecount @ipv4databasecount end |
#ipv4indexbaseaddr ⇒ Object
Returns the value of attribute ipv4indexbaseaddr.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def ipv4indexbaseaddr @ipv4indexbaseaddr end |
#ipv6databaseaddr ⇒ Object
Returns the value of attribute ipv6databaseaddr.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def ipv6databaseaddr @ipv6databaseaddr end |
#ipv6databasecount ⇒ Object
Returns the value of attribute ipv6databasecount.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def ipv6databasecount @ipv6databasecount end |
#ipv6indexbaseaddr ⇒ Object
Returns the value of attribute ipv6indexbaseaddr.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def ipv6indexbaseaddr @ipv6indexbaseaddr end |
#last_err_msg ⇒ Object
Returns the value of attribute last_err_msg.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def last_err_msg @last_err_msg end |
#record ⇒ Object
Returns the value of attribute record.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def record @record end |
#record_class4 ⇒ Object
Returns the value of attribute record_class4.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def record_class4 @record_class4 end |
#record_class6 ⇒ Object
Returns the value of attribute record_class6.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def record_class6 @record_class6 end |
#v4 ⇒ Object
Returns the value of attribute v4.
15 16 17 |
# File 'lib/ip2location_ruby.rb', line 15 def v4 @v4 end |
Instance Method Details
#close ⇒ Object
63 64 65 |
# File 'lib/ip2location_ruby.rb', line 63 def close() self.file.close end |
#get_addresstype(ip) ⇒ Object
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
# File 'lib/ip2location_ruby.rb', line 597 def get_addresstype(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN addresstype = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) addresstype = (defined?(rec.addresstype) && rec.addresstype != '') ? rec.addresstype : FIELD_NOT_SUPPORTED else addresstype = INVALID_IP_ADDRESS end else addresstype = INVALID_IP_ADDRESS end return addresstype end |
#get_all(ip) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 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 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/ip2location_ruby.rb', line 118 def get_all(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN country_short = IPV6_ADDRESS_IN_IPV4_BIN country_long = IPV6_ADDRESS_IN_IPV4_BIN region = IPV6_ADDRESS_IN_IPV4_BIN city = IPV6_ADDRESS_IN_IPV4_BIN latitude = IPV6_ADDRESS_IN_IPV4_BIN longitude = IPV6_ADDRESS_IN_IPV4_BIN isp = IPV6_ADDRESS_IN_IPV4_BIN domain = IPV6_ADDRESS_IN_IPV4_BIN netspeed = IPV6_ADDRESS_IN_IPV4_BIN areacode = IPV6_ADDRESS_IN_IPV4_BIN iddcode = IPV6_ADDRESS_IN_IPV4_BIN timezone = IPV6_ADDRESS_IN_IPV4_BIN zipcode = IPV6_ADDRESS_IN_IPV4_BIN weatherstationname = IPV6_ADDRESS_IN_IPV4_BIN weatherstationcode = IPV6_ADDRESS_IN_IPV4_BIN mcc = IPV6_ADDRESS_IN_IPV4_BIN mnc = IPV6_ADDRESS_IN_IPV4_BIN mobilebrand = IPV6_ADDRESS_IN_IPV4_BIN elevation = IPV6_ADDRESS_IN_IPV4_BIN usagetype = IPV6_ADDRESS_IN_IPV4_BIN addresstype = IPV6_ADDRESS_IN_IPV4_BIN category = IPV6_ADDRESS_IN_IPV4_BIN district = IPV6_ADDRESS_IN_IPV4_BIN asn = IPV6_ADDRESS_IN_IPV4_BIN as = IPV6_ADDRESS_IN_IPV4_BIN elsif !(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 latitude = (defined?(rec.latitude) && rec.latitude != '') ? rec.latitude : FIELD_NOT_SUPPORTED longitude = (defined?(rec.longitude) && rec.longitude != '') ? rec.longitude : FIELD_NOT_SUPPORTED isp = (defined?(rec.isp) && rec.isp != '') ? rec.isp : FIELD_NOT_SUPPORTED domain = (defined?(rec.domain) && rec.domain != '') ? rec.domain : FIELD_NOT_SUPPORTED netspeed = (defined?(rec.netspeed) && rec.netspeed != '') ? rec.netspeed : FIELD_NOT_SUPPORTED areacode = (defined?(rec.areacode) && rec.areacode != '') ? rec.areacode : FIELD_NOT_SUPPORTED iddcode = (defined?(rec.iddcode) && rec.iddcode != '') ? rec.iddcode : FIELD_NOT_SUPPORTED timezone = (defined?(rec.timezone) && rec.timezone != '') ? rec.timezone : FIELD_NOT_SUPPORTED zipcode = (defined?(rec.zipcode) && rec.zipcode != '') ? rec.zipcode : FIELD_NOT_SUPPORTED weatherstationname = (defined?(rec.weatherstationname) && rec.weatherstationname != '') ? rec.weatherstationname : FIELD_NOT_SUPPORTED weatherstationcode = (defined?(rec.weatherstationcode) && rec.weatherstationcode != '') ? rec.weatherstationcode : FIELD_NOT_SUPPORTED mcc = (defined?(rec.mcc) && rec.mcc != '') ? rec.mcc : FIELD_NOT_SUPPORTED mnc = (defined?(rec.mnc) && rec.mnc != '') ? rec.mnc : FIELD_NOT_SUPPORTED mobilebrand = (defined?(rec.mobilebrand) && rec.mobilebrand != '') ? rec.mobilebrand : FIELD_NOT_SUPPORTED elevation = (defined?(rec.elevation) && rec.elevation != '') ? rec.elevation : FIELD_NOT_SUPPORTED usagetype = (defined?(rec.usagetype) && rec.usagetype != '') ? rec.usagetype : FIELD_NOT_SUPPORTED addresstype = (defined?(rec.addresstype) && rec.addresstype != '') ? rec.addresstype : FIELD_NOT_SUPPORTED category = (defined?(rec.category) && rec.category != '') ? rec.category : FIELD_NOT_SUPPORTED district = (defined?(rec.district) && rec.district != '') ? rec.district : 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 else country_short = INVALID_IP_ADDRESS country_long = INVALID_IP_ADDRESS region = INVALID_IP_ADDRESS city = INVALID_IP_ADDRESS latitude = INVALID_IP_ADDRESS longitude = INVALID_IP_ADDRESS isp = INVALID_IP_ADDRESS domain = INVALID_IP_ADDRESS netspeed = INVALID_IP_ADDRESS areacode = INVALID_IP_ADDRESS iddcode = INVALID_IP_ADDRESS timezone = INVALID_IP_ADDRESS zipcode = INVALID_IP_ADDRESS weatherstationname = INVALID_IP_ADDRESS weatherstationcode = INVALID_IP_ADDRESS mcc = INVALID_IP_ADDRESS mnc = INVALID_IP_ADDRESS mobilebrand = INVALID_IP_ADDRESS elevation = INVALID_IP_ADDRESS usagetype = INVALID_IP_ADDRESS addresstype = INVALID_IP_ADDRESS category = INVALID_IP_ADDRESS district = INVALID_IP_ADDRESS asn = INVALID_IP_ADDRESS as = INVALID_IP_ADDRESS end else country_short = INVALID_IP_ADDRESS country_long = INVALID_IP_ADDRESS region = INVALID_IP_ADDRESS city = INVALID_IP_ADDRESS latitude = INVALID_IP_ADDRESS longitude = INVALID_IP_ADDRESS isp = INVALID_IP_ADDRESS domain = INVALID_IP_ADDRESS netspeed = INVALID_IP_ADDRESS areacode = INVALID_IP_ADDRESS iddcode = INVALID_IP_ADDRESS timezone = INVALID_IP_ADDRESS zipcode = INVALID_IP_ADDRESS weatherstationname = INVALID_IP_ADDRESS weatherstationcode = INVALID_IP_ADDRESS mcc = INVALID_IP_ADDRESS mnc = INVALID_IP_ADDRESS mobilebrand = INVALID_IP_ADDRESS elevation = INVALID_IP_ADDRESS usagetype = INVALID_IP_ADDRESS addresstype = INVALID_IP_ADDRESS category = INVALID_IP_ADDRESS district = INVALID_IP_ADDRESS asn = INVALID_IP_ADDRESS as = INVALID_IP_ADDRESS end results = {} results['country_short'] = country_short results['country_long'] = country_long results['region'] = region results['city'] = city results['latitude'] = latitude results['longitude'] = longitude results['isp'] = isp results['domain'] = domain results['netspeed'] = netspeed results['areacode'] = areacode results['iddcode'] = iddcode results['timezone'] = timezone results['zipcode'] = zipcode results['weatherstationname'] = weatherstationname results['weatherstationcode'] = weatherstationcode results['mcc'] = mcc results['mnc'] = mnc results['mobilebrand'] = mobilebrand results['elevation'] = elevation results['usagetype'] = usagetype results['addresstype'] = addresstype results['category'] = category results['district'] = district results['asn'] = asn results['as'] = as return results end |
#get_areacode(ip) ⇒ Object
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'lib/ip2location_ruby.rb', line 461 def get_areacode(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN areacode = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) areacode = (defined?(rec.areacode) && rec.areacode != '') ? rec.areacode : FIELD_NOT_SUPPORTED else areacode = INVALID_IP_ADDRESS end else areacode = INVALID_IP_ADDRESS end return areacode end |
#get_as(ip) ⇒ Object
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/ip2location_ruby.rb', line 665 def get_as(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN as = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) as = (defined?(rec.as) && rec.as != '') ? rec.as : FIELD_NOT_SUPPORTED else as = INVALID_IP_ADDRESS end else as = INVALID_IP_ADDRESS end return as end |
#get_asn(ip) ⇒ Object
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 |
# File 'lib/ip2location_ruby.rb', line 648 def get_asn(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN asn = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) asn = (defined?(rec.asn) && rec.asn != '') ? rec.asn : FIELD_NOT_SUPPORTED else asn = INVALID_IP_ADDRESS end else asn = INVALID_IP_ADDRESS end return asn end |
#get_category(ip) ⇒ Object
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
# File 'lib/ip2location_ruby.rb', line 614 def get_category(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN category = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) category = (defined?(rec.category) && rec.category != '') ? rec.category : FIELD_NOT_SUPPORTED else category = INVALID_IP_ADDRESS end else category = INVALID_IP_ADDRESS end return category end |
#get_city(ip) ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/ip2location_ruby.rb', line 308 def get_city(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN city = IPV6_ADDRESS_IN_IPV4_BIN elsif !(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
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/ip2location_ruby.rb', line 274 def get_country_long(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN country_long = IPV6_ADDRESS_IN_IPV4_BIN elsif !(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
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/ip2location_ruby.rb', line 257 def get_country_short(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN country_short = IPV6_ADDRESS_IN_IPV4_BIN elsif !(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
79 80 81 |
# File 'lib/ip2location_ruby.rb', line 79 def get_database_version() return (self.databaseyear).to_s + "." + (self.databasemonth).to_s + "." + (self.databaseday).to_s end |
#get_district(ip) ⇒ Object
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 |
# File 'lib/ip2location_ruby.rb', line 631 def get_district(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN district = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) district = (defined?(rec.district) && rec.district != '') ? rec.district : FIELD_NOT_SUPPORTED else district = INVALID_IP_ADDRESS end else district = INVALID_IP_ADDRESS end return district end |
#get_domain(ip) ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/ip2location_ruby.rb', line 376 def get_domain(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN domain = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) domain = (defined?(rec.domain) && rec.domain != '') ? rec.domain : FIELD_NOT_SUPPORTED else domain = INVALID_IP_ADDRESS end else domain = INVALID_IP_ADDRESS end return domain end |
#get_elevation(ip) ⇒ Object
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/ip2location_ruby.rb', line 563 def get_elevation(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN elevation = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) elevation = (defined?(rec.elevation) && rec.elevation != '') ? rec.elevation : FIELD_NOT_SUPPORTED else elevation = INVALID_IP_ADDRESS end else elevation = INVALID_IP_ADDRESS end return elevation end |
#get_iddcode(ip) ⇒ Object
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/ip2location_ruby.rb', line 444 def get_iddcode(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN iddcode = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) iddcode = (defined?(rec.iddcode) && rec.iddcode != '') ? rec.iddcode : FIELD_NOT_SUPPORTED else iddcode = INVALID_IP_ADDRESS end else iddcode = INVALID_IP_ADDRESS end return iddcode end |
#get_isp(ip) ⇒ Object
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/ip2location_ruby.rb', line 359 def get_isp(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN isp = IPV6_ADDRESS_IN_IPV4_BIN elsif !(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_last_error_message ⇒ Object
67 68 69 |
# File 'lib/ip2location_ruby.rb', line 67 def () return self.last_err_msg end |
#get_latitude(ip) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/ip2location_ruby.rb', line 325 def get_latitude(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN latitude = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) latitude = (defined?(rec.latitude) && rec.latitude != '') ? rec.latitude : FIELD_NOT_SUPPORTED else latitude = INVALID_IP_ADDRESS end else latitude = INVALID_IP_ADDRESS end return latitude end |
#get_longitude(ip) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/ip2location_ruby.rb', line 342 def get_longitude(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN longitude = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) longitude = (defined?(rec.longitude) && rec.longitude != '') ? rec.longitude : FIELD_NOT_SUPPORTED else longitude = INVALID_IP_ADDRESS end else longitude = INVALID_IP_ADDRESS end return longitude end |
#get_mcc(ip) ⇒ Object
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/ip2location_ruby.rb', line 512 def get_mcc(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN mcc = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) mcc = (defined?(rec.mcc) && rec.mcc != '') ? rec.mcc : FIELD_NOT_SUPPORTED else mcc = INVALID_IP_ADDRESS end else mcc = INVALID_IP_ADDRESS end return mcc end |
#get_mnc(ip) ⇒ Object
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/ip2location_ruby.rb', line 529 def get_mnc(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN mnc = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) mnc = (defined?(rec.mnc) && rec.mnc != '') ? rec.mnc : FIELD_NOT_SUPPORTED else mnc = INVALID_IP_ADDRESS end else mnc = INVALID_IP_ADDRESS end return mnc end |
#get_mobilebrand(ip) ⇒ Object
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
# File 'lib/ip2location_ruby.rb', line 546 def get_mobilebrand(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN mobilebrand = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) mobilebrand = (defined?(rec.mobilebrand) && rec.mobilebrand != '') ? rec.mobilebrand : FIELD_NOT_SUPPORTED else mobilebrand = INVALID_IP_ADDRESS end else mobilebrand = INVALID_IP_ADDRESS end return mobilebrand end |
#get_module_version ⇒ Object
71 72 73 |
# File 'lib/ip2location_ruby.rb', line 71 def get_module_version() return VERSION end |
#get_netspeed(ip) ⇒ Object
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/ip2location_ruby.rb', line 427 def get_netspeed(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN netspeed = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) netspeed = (defined?(rec.netspeed) && rec.netspeed != '') ? rec.netspeed : FIELD_NOT_SUPPORTED else netspeed = INVALID_IP_ADDRESS end else netspeed = INVALID_IP_ADDRESS end return netspeed end |
#get_package_version ⇒ Object
75 76 77 |
# File 'lib/ip2location_ruby.rb', line 75 def get_package_version() return (self.db_index).to_s end |
#get_region(ip) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/ip2location_ruby.rb', line 291 def get_region(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN region = IPV6_ADDRESS_IN_IPV4_BIN elsif !(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 |
#get_timezone(ip) ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/ip2location_ruby.rb', line 410 def get_timezone(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN timezone = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) timezone = (defined?(rec.timezone) && rec.timezone != '') ? rec.timezone : FIELD_NOT_SUPPORTED else timezone = INVALID_IP_ADDRESS end else timezone = INVALID_IP_ADDRESS end return timezone end |
#get_usagetype(ip) ⇒ Object
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/ip2location_ruby.rb', line 580 def get_usagetype(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN usagetype = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) usagetype = (defined?(rec.usagetype) && rec.usagetype != '') ? rec.usagetype : FIELD_NOT_SUPPORTED else usagetype = INVALID_IP_ADDRESS end else usagetype = INVALID_IP_ADDRESS end return usagetype end |
#get_weatherstationcode(ip) ⇒ Object
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/ip2location_ruby.rb', line 478 def get_weatherstationcode(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN weatherstationcode = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) weatherstationcode = (defined?(rec.weatherstationcode) && rec.weatherstationcode != '') ? rec.weatherstationcode : FIELD_NOT_SUPPORTED else weatherstationcode = INVALID_IP_ADDRESS end else weatherstationcode = INVALID_IP_ADDRESS end return weatherstationcode end |
#get_weatherstationname(ip) ⇒ Object
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/ip2location_ruby.rb', line 495 def get_weatherstationname(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN weatherstationname = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) weatherstationname = (defined?(rec.weatherstationname) && rec.weatherstationname != '') ? rec.weatherstationname : FIELD_NOT_SUPPORTED else weatherstationname = INVALID_IP_ADDRESS end else weatherstationname = INVALID_IP_ADDRESS end return weatherstationname end |
#get_zipcode(ip) ⇒ Object
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/ip2location_ruby.rb', line 393 def get_zipcode(ip) valid = !(IPAddr.new(ip) rescue nil).nil? if valid rec = get_record(ip) if rec == IPV6_ADDRESS_IN_IPV4_BIN zipcode = IPV6_ADDRESS_IN_IPV4_BIN elsif !(rec.nil?) zipcode = (defined?(rec.zipcode) && rec.zipcode != '') ? rec.zipcode : FIELD_NOT_SUPPORTED else zipcode = INVALID_IP_ADDRESS end else zipcode = INVALID_IP_ADDRESS end return zipcode end |
#open(url) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ip2location_ruby.rb', line 23 def open(url) if url == '' self.last_err_msg = 'Ip2location.new.open() requires a database path name.' abort('Ip2location.new.open() requires a database path name.') end begin self.file = File.open(File. url, 'rb') rescue self.last_err_msg = 'Ip2location.new.open() error in opening ' + url + '.' abort('Ip2location.new.open() error in opening ' + url + '. No such file in the /your_ip2location_ruby_library_path/rb/ folder.') else end i2l = Ip2locationConfig.read(file) if i2l.productcode == 1 else if i2l.databaseyear <= 20 && i2l.productcode == 0 else self.file.close self.last_err_msg = INVALID_BIN_DATABASE abort(INVALID_BIN_DATABASE) end end self.db_index = i2l.databasetype self.columns = i2l.databasecolumn + 0 self.databaseyear = 2000 + i2l.databaseyear self.databasemonth = i2l.databasemonth self.databaseday = i2l.databaseday self.database = DbConfig.setup_database(self.db_index) self.ipv4databasecount = i2l.ipv4databasecount self.ipv4databaseaddr = i2l.ipv4databaseaddr self.ipv6databasecount = i2l.ipv6databasecount self.ipv6databaseaddr = i2l.ipv6databaseaddr self.ipv4indexbaseaddr = i2l.ipv4indexbaseaddr self.ipv6indexbaseaddr = i2l.ipv6indexbaseaddr self.record_class4 = (Ip2LocationRecord.init database, 4) self.record_class6 = (Ip2LocationRecord.init database, 6) self end |
#validateip(ip) ⇒ Object
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'lib/ip2location_ruby.rb', line 714 def validateip(ip) if ip.ipv4? ipv = 4 ipnum = ip.to_i + 0 else ipv = 6 ipnum = ip.to_i + 0 #reformat ipv4 address in ipv6 if ipnum >= 281470681743360 && ipnum <= 281474976710655 ipv = 4 ipnum = ipnum - 281470681743360 end #reformat 6to4 address to ipv4 address 2002:: to 2002:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF if ipnum >= 42545680458834377588178886921629466624 && ipnum <= 42550872755692912415807417417958686719 ipv = 4 #bitshift right 80 bits ipnum = ipnum >> 80 #bitwise modulus to get the last 32 bit ipnum = ipnum % 4294967296 end #reformat Teredo address to ipv4 address 2001:0000:: to 2001:0000:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF: if ipnum >= 42540488161975842760550356425300246528 && ipnum <= 42540488241204005274814694018844196863 ipv = 4 #bitwise not to invert binary ipnum = ~ipnum #bitwise modulus to get the last 32 bit ipnum = ipnum % 4294967296 end end [ipv, ipnum] end |