IT
[Java] MaxMind: GeoLite Country API 이용하여 IP 주소로 국가코드 검색하기
정미나
2011. 7. 6. 17:49
* GeoLite Country: MaxMind에서 오픈소스로 제공하는 국가별 IP 체크 라이브러리
☞ http://www.maxmind.com
1. 다운로드 받기
☞ http://www.maxmind.com/app/geolitecountry
- 표시된 부분을 클릭하여 GeoIP.dat과 GeoIPJava-1.2.4를 다운
(Java를 비롯한 C, PHP, C# 등등 여러 언어를 지원)
2. GeoIP.dat 파일을 적절한 경로에 넣고 GeoIPJava-1.2.4/source/com 폴더를 프로젝트 폴더로 복사
3. 소스파일
☞ http://www.maxmind.com
1. 다운로드 받기
☞ http://www.maxmind.com/app/geolitecountry
- 표시된 부분을 클릭하여 GeoIP.dat과 GeoIPJava-1.2.4를 다운
(Java를 비롯한 C, PHP, C# 등등 여러 언어를 지원)
2. GeoIP.dat 파일을 적절한 경로에 넣고 GeoIPJava-1.2.4/source/com 폴더를 프로젝트 폴더로 복사
3. 소스파일
import com.maxmind.geoip.LookupService;
.
.
.
LookupService lookup = null;
try {
lookup = new LookupService("/GeoIP.dat 경로", LookupService.GEOIP_MEMORY_CACHE);
} catch(IOException e) {
e.printStackTrace(System.out);
}
String ipZoneCd = lookup.getCountry("IP주소").getCode();
String ipZoneNm = lookup.getCountry("IP주소").getName();
.
.
.
LookupService lookup = null;
try {
lookup = new LookupService("/GeoIP.dat 경로", LookupService.GEOIP_MEMORY_CACHE);
} catch(IOException e) {
e.printStackTrace(System.out);
}
String ipZoneCd = lookup.getCountry("IP주소").getCode();
String ipZoneNm = lookup.getCountry("IP주소").getName();