====== GeoIP ====== - 웹주소 : [[http://www.maxmind.com/app/geolitecountry|링크]] - 다운로드 주소 : [[http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip|링크]] - CSV를 사용한 IP 검사 : [[http://www.maxmind.com/app/csv|링크]] - GeoIP를 활용하는 방식 : [[http://www.maxmind.com/app/geoip_resources|링크]] ====== GeoIP 검사시, 숫자로 변경 하는 방식 ====== * from [[http://www.maxmind.com/app/csv|링크]] CSV 파일 포맷: "begin_ip","end_ip","begin_num","end_num","country","name" "61.88.0.0","61.91.255.255","1029177344","1029439487","AU","Australia" "61.92.0.0","61.93.255.255","1029439488","1029570559","HK","Hong Kong" "61.94.0.0","61.94.7.255","1029570560","1029572607","ID","Indonesia" Beginning IP Number, Ending IP Number의 계산 방법: ipnum = 16777216*w + 65536*x + 256*y + z where IP Address = w.x.y.z 숫자에서 IP로 변경하는 방식: w = int ( ipnum / 16777216 ) % 256; x = int ( ipnum / 65536 ) % 256; y = int ( ipnum / 256 ) % 256; z = int ( ipnum ) % 256; Where % is the mod operator. Here is sample Perl code to convert the IP number to a IP address: sub numToStr { my ($ipnum) = @_; my $z = $ipnum % 256; $ipnum >>= 8; my $y = $ipnum % 256; $ipnum >>= 8; my $x = $ipnum % 256; $ipnum >>= 8; my $w = $ipnum % 256; return "$w.$x.$y.$z"; } **SQL Query** SELECT ip_country FROM geoip WHERE 404232216 BETWEEN begin_ip_num AND end_ip_num LIMIT 1 **MySQL Query** SELECT ip_country FROM geoip WHERE 404232216 >= begin_ip_num AND 404232216 <= end_ip_num LIMIT 1