项目作者: delef

项目描述 :
MaxMind GeoIP2 Reader for Crystal
高级语言: Crystal
项目地址: git://github.com/delef/geoip2.cr.git
创建时间: 2019-02-07T13:05:31Z
项目社区:https://github.com/delef/geoip2.cr

开源协议:MIT License

下载


GeoIP2.cr

Built with Crystal
Build Status
Releases

Pure Crystal GeoIP2 databases reader.

Installation

Add this to your application’s shard.yml:

  1. dependencies:
  2. geoip2:
  3. github: delef/geoip2.cr

Usage

Country Example

  1. require "geoip2"
  2. reader = GeoIP2.open("/path/to/GeoLite2-Country.mmdb")
  3. record = reader.country("128.101.101.101")
  4. record.country.iso_code # => "US"
  5. record.country.in_european_union? # => false
  6. record.country.name # => "United States"
  7. record.country.names["de"] # => "USA"
  8. record.continent.code # => "NA"
  9. record.continent.name # => "North America"
  10. record.registered_country.iso_code # => "US"
  11. record.registered_country.name # => "United States"

City Example

  1. require "geoip2"
  2. reader = GeoIP2.open("/path/to/GeoLite2-City.mmdb", ["en", "ru", "de"])
  3. record = reader.city("128.101.101.101")
  4. record.city.geoname_id # => 5045360
  5. record.city.name # => "Minneapolis"
  6. record.city.names["ru"] # => "Миннеаполис"
  7. record.country.iso_code # => "US"
  8. record.country.in_european_union? # => false
  9. record.country.name # => "United States"
  10. record.country.names["de"] # => "USA"
  11. record.continent.code # => "NA"
  12. record.continent.name # => "North America"
  13. record.location.accuracy_radius # => 20
  14. record.location.latitude # => 44.9532
  15. record.location.longitude # => -93.158
  16. record.location.metro_code # => 613
  17. record.location.time_zone # => "America/Chicago"
  18. record.postal.code # => "55104"
  19. record.registered_country.iso_code # => "US"
  20. record.registered_country.name # => "United States"
  21. record.subdivisions[0].iso_code # => "MN"
  22. record.subdivisions[0].name # => "Minnesota"

Enterprise Example

  1. require "geoip2"
  2. reader = GeoIP2.open("/path/to/GeoIP2-Enterprise.mmdb")
  3. record = reader.enterprise("128.101.101.101")
  4. record.city.name # => "Minneapolis"
  5. record.city.confidence # => 60
  6. record.country.iso_code # => "US"
  7. record.country.name # => "United States"
  8. record.country.names["zh-CN"] # => "美国"
  9. record.country.confidence # => 99
  10. record.subdivisions[0].name # => "Minnesota"
  11. record.subdivisions[0].iso_code # => "MN"
  12. record.subdivisions[0].confidence # => 77
  13. record.postal.code # => "55455"
  14. record.postal.confidence # => "55455"
  15. record.location.latitude # => 44.9733
  16. record.location.longitude # => -93.2323
  17. record.location.accuracy_radius # => 50

Anonymous IP Example

  1. require "geoip2"
  2. reader = GeoIP2.open("/path/to/GeoIP2-Anonymous-IP.mmdb")
  3. record = reader.anonymous_ip("128.101.101.101")
  4. record.anonymous? # => false
  5. record.anonymous_vpn? # => false
  6. record.hosting_provider? # => false
  7. record.public_proxy? # => false
  8. record.tor_exit_node? # => false
  9. record.ip_address # => "128.101.101.101"

Connection-Type Example

  1. require "geoip2"
  2. reader = GeoIP2.open("/path/to/GeoIP2-Connection-Type.mmdb")
  3. record = reader.connection_type("128.101.101.101")
  4. record.connection_type # => "Corporate"
  5. record.ip_address # => "128.101.101.101"

Domain Example

  1. require "geoip2"
  2. reader = GeoIP2.open("/path/to/GeoIP2-Domain.mmdb")
  3. record = reader.domain("128.101.101.101")
  4. record.domain # => "umn.edu"
  5. record.ip_address # => "128.101.101.101"

ISP Example

  1. require "geoip2"
  2. reader = GeoIP2.open("/path/to/GeoIP2-ISP.mmdb")
  3. record = reader.isp("128.101.101.101")
  4. record.autonomous_system_number # => 217
  5. record.autonomous_system_organization # => "University of Minnesota"
  6. record.isp # => "University of Minnesota"
  7. record.organization # => "University of Minnesota"
  8. record.ip_address # => "128.101.101.101"

Contributing

  1. Fork it ( https://github.com/delef/geoip2.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am ‘Add some feature’)
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request