IP대역 별 국가확인
1. GeoIP.dat 다운로드 - http://www.maxmind.com/app/geolitecountry
2. geoip.inc 다운로드 - https://github.com/maxmind/geoip-api-php ->
https://github.com/maxmind/geoip-api-php/blob/master/src/geoip.inc
Download links |
|
Database |
Binary / gzip |
GeoLite Country |
|
GeoLite Country IPv6 |
|
GeoLite City |
|
GeoLite City IPv6 (Beta) |
|
GeoLite ASN |
|
GeoLite ASN IPv6 |
GeoIP Legacy Downloadable Databases
<? include("./geoip.inc"); $gi = geoip_open("./GeoIP.dat", GEOIP_STANDARD); // GeoIP.dat 파일 주소 $ip = $_SERVER[REMOTE_ADDR];
if (geoip_country_code_by_addr($gi, $ip) == "JP") { echo '일본' ; } echo geoip_country_code_by_addr($gi, $ip)."<br>"; echo geoip_country_name_by_addr($gi, $ip); geoip_close($gi); ?> 아래는 whois 를 통해 실시간으로 체크하는 방법이다. <? $domain = "216.255.255.255"; //북미 $fp = fsockopen("whois.nida.or.kr",43); if($fp){ fputs($fp,"$domain\n"); while(!feof($fp)){ $result .= fgets($fp,80); } if(ereg("whois\.arin\.net",$result)){ echo "북미<br>"; }else if(ereg("whois\.apnic\.net",$result)){ echo "해외<br>"; }else{ echo "국내<br>"; } $result = nl2br($result); echo $result; }else{ echo "fail"; } ?> |