'geoip-lite'에 해당되는 글 1건

  1. 2015.03.19 [node.js] GeoIP 사용하기 ip로 간략하게 위치 정보 확인
Programming/node.js2015.03.19 15:18

node.js에서 간략하게 IP기반으로 사용자 (위치) 지역 정보 데이터 분석용으로 GeoIP 라이브러리 있나 찾아봤음


역시 라이브러리 geoip-lite 라고 있음!!


Github : https://github.com/bluesmoon/node-geoip


1. 설치방법

$ npm install geoip-lite


2. 코드작성 및 사용법

$ vi geoip.js
=====================================
var geoip = require('geoip-lite');
var ip = "207.97.227.239";
var geo = geoip.lookup(ip);
console.log(geo);
====================================
$ node geoip.js 
{ range: [ 3479297920, 3479301339 ],
  country: 'US',
  region: 'TX',
  city: 'San Antonio',
  ll: [ 29.4889, -98.3987 ],
  metro: 641 }

※ ll 배열값에서 ll: [<latitude(위도)>, <longitude(경도)>] 순서임!!


3. GeoIP 정보 업데이트방법

※ github보면 geoip.startWatchingDataUpdate(); 함수로도 가능한데 아래 script로 하는게 더 낫은듯함

$ cd /usr/lib/node_modules/geoip-lite
$ npm run-script updatedb

> geoip-lite@1.1.5 updatedb /usr/lib/node_modules/geoip-lite
> node scripts/updatedb.js
Retrieving GeoIPCountryCSV.zip ... DONE
Extracting GeoIPCountryCSV.zip ... DONE
Processing Data (may take a moment) ...
Still working (96813) ... DONE
Retrieving GeoIPv6.csv ... DONE
Processing Data (may take a moment) ... DONE
Retrieving GeoLiteCity-latest.zip ... DONE
Extracting GeoLiteCity-latest.zip ... DONE
Processing Data (may take a moment) ...
Still working (122762) ...
Still working (246870) ...
Still working (368626) ...
Still working (490380) ...
Still working (612413) ...
Still working (734688) ...
Still working (855126) ...
Still working (977268) ...
Still working (1096307) ...
Still working (1217573) ...
Still working (1339167) ...
Still working (1459608) ...
Still working (1580033) ...
Still working (1700173) ...
Still working (1822030) ...
Still working (1943449) ... DONE
Retrieving GeoLiteCityv6.csv ... DONE
Processing Data (may take a moment) ... DONE
Successfully Updated Databases from MaxMind.


※ https://github.com/PaddeK/node-maxmind-db 추가 라이브러리(동일하게 MaxMind DB 기반이긴함) 

Posted by 시니^^

티스토리 툴바