Skip to content

This is a REST API built using node.js version 8.11.2 and MySQL as database.

Notifications You must be signed in to change notification settings

aratidgr8/iptocountry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iptocountry

This is a REST API built using node.js version 8.11.2, express framework and MySQL database, which fetches user's public IP address and finds his (2 character)country code, country name, state/region and city name and returns result in JSON format.

Steps to install

  1. You can clone using command
    git clone https://github.com/aratidgr8/iptocountry.git;
    or
    Download iptocountry-master.zip file.

  2. Navigate to folder in terminal or command line interface.

  3. To install all node modules and their dependencies required in code, from package.json file, run below command:
    npm install

  4. Unzip csv-databases.zip folder.

  5. Move IP2LOCATION-LITE-DB3.CSV and IP2LOCATION-LITE-DB3.IPV6.CSV files from csv-databases directory to root folder (same folder, where csv2sql.php file is present).

  6. Create database ip2location
    CREATE DATABASE ip2location;

  7. Create table ip2location_db3 which stores; IPV4, country code, country name, state and city name information.
    CREATE TABLE ip2location_db3(ip_from INT(10) UNSIGNED,ip_to INT(10) UNSIGNED,country_code CHAR(2), country_name VARCHAR(64), region_name VARCHAR(128), city_name VARCHAR(128), INDEX idx_ip_from (ip_from),INDEX idx_ip_to (ip_to),INDEX idx_ip_from_to (ip_from, ip_to)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

  8. Create table ip2location_db3_ipv6 which stores; IPV6, country code, country name, state and city name information.
    CREATE TABLE ip2location_db3_ipv6(ip_from DECIMAL(39,0) UNSIGNED NULL DEFAULT NULL,ip_to DECIMAL(39,0) UNSIGNED NOT NULL,country_code CHAR(2),country_name VARCHAR(64),region_name VARCHAR(128),city_name VARCHAR(128), INDEX idx_ip_from (ip_from), INDEX idx_ip_to (ip_to), INDEX idx_ip_from_to (ip_from, ip_to)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

  9. Open csv2sql.php file on your localhost and submit form to import data from CSV file IP2LOCATION-LITE-DB3.CSV to Mysql table: ip2location_db3.
    It should load table ip2location_db3 with 3278000 rows.

  10. In csv2sql.php file now change the "table name" input to ip2location_db3_ipv6 and "Name of the file" input to IP2LOCATION-LITE-DB3.IPV6.CSV and submit the form once again.
    It should load table ip2location_db3_ipv6 with 3719942 rows.

  11. Go to terminal and run below command:
    node app.js

  12. Now, go to the browser and load below URL:
    http://localhost:4001/api/v1/userscountry

  13. Script fetched your IP address and returns your location information in JSON format as below:
    {"country_code":"IN","country_name":"India","region_name":"Gujarat","city_name":"Chanasma"}

About

This is a REST API built using node.js version 8.11.2 and MySQL as database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published