위치 추적은 위성을 이용하여 과거 군사용으로 사용됐다. 70년대 후반 GPS(Global Positioning System)의 등장으로 삼각측량법에 기반해 위성의 도움으로 정확한 위치를 추적할 수 있게 되었고 오늘날 민간인이 실시간으로 사용하기까지 그리 오래 걸리지 않았다. 인터넷에서 위치는 IP 주소로 확인할 수 있는데 이에 기반한 물리적 주소를 알 수 있을까?
IPv4에 정의한 프로토콜은 국제 표준화 기구인 IETF(Internet Engineering Task Force)에서 1981년 공표한 문서 RFC791를 보면 (http://www.ietf.org/rfc/rfc791.txt) 확인할 수 있다. 헤더에서 출발지와 목적지 IP는 각각 32비트로 정의해 이론적으로 2^32=4,294,947,296개를 사용할 수 있으나 실제는 그보다 더 적은 수의 IP만 사용 가능하다. 이는 Special Use IPv4 Addresses라는 RFC5735(http://tools.ietf.org/html/rfc5735)와 RFC1918(http://tools.ietf.org/html/rfc1918)에서 확인할 수 있다. 또한 이 IP는 IANA(Internet Assigned Numbers Authority, http://www.iana.org)라는 비영리기구에서 관할한다.
Tracing location has been mainly used for the military operation purpose. In the late 70’s, the advent of GPS, Global Positioning System, allows people to accurately trace targets with the help of a satellite. Today civilians are permitted to be of use for their own interests. By checking IP(Internet Protocol) address, one is able to recognize the other on the Internet. Then how are we aware of the physical location based on this information, IP address? Well, RFC791 has well defined and explained how it works. It allocated 32 bytes in source and destination IP version 4, which means there are approximately four billion IPs available theoretically. However standard organization has predefined some IPs for special use.(Refer to RFC5735 and RFC1918). The IANA(Internet Assigned Numbers Authority) has administered the entire block of IP addresses.
오늘날 가장 대중적으로 이용되는 방식은 Maxmind사 (http://www.maxmind.com)의 GeoIP라는 데이터베이스를 사용해서 물리적 위치를 찾는다. 해당 웹사이트에 따르면 국가기반은 99.8%, 주 수준은 90%, 도시 수준으로는 83%의 정확도를 가진다고 한다. 하지만 구글 어스를 통해 검색하면 훨씬 정확한 위치를 얻어낼 수 있음을 보면 매우 상세한 DB를 가지고 있으리라 추정된다. 2012년 2월 기준으로 데이터베이스에 약 15만개의 국가 수준의 IP 블럭을 소유하고 있고 전체 IP수는 34억 3100만여개, 등록국가는 248개이다. (http://www.maxmind.com/app/techinfo) 현재 시점에서 당연히 또 변화가 있을 것이다. 다음 주소에서 무료 CSV 파일로 제공하니 궁금한 사람은 직접 다운받아 보도록 하자.
http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
http://geolite.maxmind.com/download/geoip/database/GeoIPv6.csv.gz
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/GeoLiteCity_20120207.zip
- XML API: http://api.ipinfodb.com/v3/ip-city/?key=<key>&ip=74.125.45.100
- JSON API: http://api.ipinfodb.com/v3/ip-city/?key=<key>&ip=74.125.45.100&format=json{ “statusCode” : “OK”,”statusMessage” : “”,”ipAddress” : “74.125.45.100”, “countryCode” : “US”, “countryName” : “UNITED STATES”, “regionName” : “GEORGIA”, “cityName” : “ATLANTA”,”zipCode” : “30301”, “latitude” : “33.809”, “longitude” : -84.3548″, “timeZone” : “-05:00“ }
GeoIP 역시 다음과 같은 언어의 API를 제공한다.
- C Library
- Perl Module
- PHP Module
- Apache Module (mod_geoip)
- Java Class
- Python Class
- C# Class
- Ruby Module
- MS COM Object?(ASP, ColdFusion, Pascal, PHP, Perl, Python, and Visual Basic code)
- VB.NET?(Only works with GeoIP Country)
- Pascal
- JavaScript
C와 Python만으로 테스트를 한 번 해 봤다. 파이선의 경우 지도에 나타낼 수 있는 라이브러리를 이용하여 지점을 표기할 수 있도록 응용할 수 있다.
Here are a couple of examples for installations and test outputs using GeoIP API with C library and Python.
A. C 라이브러리를 이용한 GeoIP API (GeoIP APIs with C Library)
# ./configure
# make; make check; make install
(2) 컴파일 (Compilation )
# gcc -lGeoIP getip.c –o getip
(3) 사용법 (Usage)
# include <GeoIP.h>
int main (int argc, char *argv[]) {
GeoIP* gi;
gi = GeoIP_new(GEOIP_STANDARD);
printf(“code %s\n“, GeoIP_country_code_by_name(gi, “yahoo.com”));
}