Giter VIP home page Giter VIP logo

geoip2.cr's Introduction

GeoIP2.cr

Built with Crystal Build Status Releases

Pure Crystal GeoIP2 databases reader.

Installation

Add this to your application's shard.yml:

dependencies:
  geoip2:
    github: delef/geoip2.cr

Usage

Country Example

require "geoip2"

reader = GeoIP2.open("/path/to/GeoLite2-Country.mmdb")
record = reader.country("128.101.101.101")

record.country.iso_code # => "US"
record.country.in_european_union? # => false
record.country.name # => "United States"
record.country.names["de"] # => "USA"

record.continent.code # => "NA"
record.continent.name # => "North America"

record.registered_country.iso_code # => "US"
record.registered_country.name # => "United States"

City Example

require "geoip2"

reader = GeoIP2.open("/path/to/GeoLite2-City.mmdb", ["en", "ru", "de"])
record = reader.city("128.101.101.101")

record.city.geoname_id # => 5045360
record.city.name # => "Minneapolis"
record.city.names["ru"] # => "Миннеаполис"

record.country.iso_code # => "US"
record.country.in_european_union? # => false
record.country.name # => "United States"
record.country.names["de"] # => "USA"

record.continent.code # => "NA"
record.continent.name # => "North America"

record.location.accuracy_radius # => 20
record.location.latitude # => 44.9532
record.location.longitude # => -93.158
record.location.metro_code # => 613
record.location.time_zone # => "America/Chicago"

record.postal.code # => "55104"

record.registered_country.iso_code # => "US"
record.registered_country.name # => "United States"

record.subdivisions[0].iso_code # => "MN"
record.subdivisions[0].name # => "Minnesota"

Enterprise Example

require "geoip2"

reader = GeoIP2.open("/path/to/GeoIP2-Enterprise.mmdb")
record = reader.enterprise("128.101.101.101")

record.city.name # => "Minneapolis"
record.city.confidence # => 60

record.country.iso_code # => "US"
record.country.name # => "United States"
record.country.names["zh-CN"] # => "美国"
record.country.confidence # => 99

record.subdivisions[0].name # => "Minnesota"
record.subdivisions[0].iso_code # => "MN"
record.subdivisions[0].confidence # => 77

record.postal.code # => "55455"
record.postal.confidence # => "55455"

record.location.latitude # => 44.9733
record.location.longitude # => -93.2323
record.location.accuracy_radius # => 50

Anonymous IP Example

require "geoip2"

reader = GeoIP2.open("/path/to/GeoIP2-Anonymous-IP.mmdb")
record = reader.anonymous_ip("128.101.101.101")

record.anonymous? # => false
record.anonymous_vpn? # => false
record.hosting_provider? # => false
record.public_proxy? # => false
record.tor_exit_node? # => false
record.ip_address # => "128.101.101.101"

Connection-Type Example

require "geoip2"

reader = GeoIP2.open("/path/to/GeoIP2-Connection-Type.mmdb")
record = reader.connection_type("128.101.101.101")

record.connection_type # => "Corporate"
record.ip_address # => "128.101.101.101"

Domain Example

require "geoip2"

reader = GeoIP2.open("/path/to/GeoIP2-Domain.mmdb")
record = reader.domain("128.101.101.101")

record.domain # => "umn.edu"
record.ip_address # => "128.101.101.101"

ISP Example

require "geoip2"

reader = GeoIP2.open("/path/to/GeoIP2-ISP.mmdb")
record = reader.isp("128.101.101.101")

record.autonomous_system_number # => 217
record.autonomous_system_organization # => "University of Minnesota"
record.isp # => "University of Minnesota"
record.organization # => "University of Minnesota"
record.ip_address # => "128.101.101.101"

Links

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

geoip2.cr's People

Contributors

delef avatar jgillich avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.