Giter Site home page Giter Site logo

iplookup's Introduction

IPLookup

Circle CI

A simple service supply API return country from an IP address.

How to works

1. Setup necessary gems and create the database for project:

bundle install
bundle exec rake db:create db:migrate

2. Config your project directory before import:

  • Edit scripts/import file - line 51 - rails_app_home function
rails_app_home () {
  cd /current/project/directory
}
  • Edit scripts/cron_import file - line 4 - rails_app_home function
rails_app_home () {
  cd /current/project/directory
}

2. Import data:

./scripts/import

3. Run server and enjoy:

bundle exec rails s

4. Run the API:

URL: localhost:3000/ipaddresses
Type: GET
Parameter: ip_addr

5. Set the cronjob:

crontab scripts/cron_import

My Notes

  1. The IP address available for free at http://download.ip2location.com/lite/. This service will auto-update the IP address every month.
  • The cronjob will auto-run at 2:00 AM on the first of every month.
  1. After download, the format of IP address is integer numbers.

  2. The Import task will import the IP address from CSV files into the database.

  3. The database will have two tables: Ipaddress and Country. The relation between two models: A country will have more IP addresses. An IP address will belong to one country.

  4. Each line in CSV files is IP addresses in a range for a country. For example: 16778240 - 16779263 - AU - Australia. So, I think we need to convert the parameter ip_addr to integer and check ip_addr is available or not in a range.

  5. How to convert the IP to integer? How to check the IP address is an IPv4 or IPv6? We can use this algorithm to converts and some Regexes for detect. But in the Ruby-core, we already have libraries for the tasks:

  • IPAddr IPAddr provides a set of methods to manipulate an IP address. Both IPv4 and IPv6 are supported.

  • Resolv IPv4 and Resolv IPv6 Resolv Ipv4 and Ipv6 will supply regex.

  1. I wrote 3 libraries:
# models/country.rb

validates :code, inclusion: { in: Countries.new.country_codes }
validates :name, inclusion: { in: Countries.new.country_names }
  • IpConverter - This library will convert the ip address to integer.

  • IpUtilities - This library supply helpful methods.

  1. I've setup the Circle CI and Ruby-Saddler to run test cases and check the coding style.

TODO

Actually, this service is built in short time, so some parts need to be improved.

  • Performance for import task progress.

  • The import script needs to refactor.

  • Need to refactor the code and write more the test cases.

iplookup's People

Contributors

vinhnglx avatar

Watchers

 avatar  avatar  avatar

Forkers

ea-collab

iplookup's Issues

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.