ip 주소로 국가 조회하는 방법 about.ip2c.org API
Open API/그 외 2018. 8. 30. 17:08
반응형
아이피주소로 국가 조회하기
서비스하는 내용이 국가별로 제한되는 부분이라
DB를 구축하자니 그 업데이트관리가 문제이고
API가 있지 않을까 해서 구글링을 통해 알게된 사이트입니다.
Request :
https://ip2c.org/8.8.8.8
Response :
1;US;USA;United States
; 로 구분자가 지정되어있으며
0 : WRONG INPUT , 1 : NORMAL , 2 : UNKNOWN
US : ISO 국가코드
아래 내용은 about.ip2c.org 사이트에서 발췌한 INPUT/OUTPUT 설명입니다.
==== Accepted inputs: ============================================================ You can use http or https. https://ip2c.org/XXX.XXX.XXX.XXX or https://ip2c.org/?ip=XXX.XXX.XXX.XXX | + standard IPv4 from 0.0.0.0 to 255.255.255.255 + e.g. we take your IP: | + URL looks like this: https://ip2c.org/128.134.3.161 | or | https://ip2c.org/?ip=128.134.3.161 | + resulting string is: 1;KR;KOR;Korea Republic of https://ip2c.org/XXXXXXXXXX or https://ip2c.org/?dec=XXXXXXXXXX | + decimal number from 0 to 4294967295 (MAX_INT) + faster than ?ip= option, less server-side processing + to convert IPv4 to decimal you only need to know this: | + (IPv4) A.B.C.D == A*256^3 + B*256^2 + C*256 + D (decimal) + e.g. 5.6.7.8 == 5*256^3 + 6*256^2 + 7*256 + 8 == 5*16777216 + 6*65536 + 7*256 + 8 == 83886080 + 393216 + 1792 + 8 == 84281096 https://ip2c.org/s or https://ip2c.org/self or https://ip2c.org/?self | + processes caller's IP + faster than ?dec= option but limited to one purpose - give info about yourself Caution Some clients (e.g. ASP) may have issues while trying to open a file over HTTP. In that case a slash / preceding ?ip= is obligatory.
==== Possible outputs: =========================================================== You can use http or https. 0;;;WRONG INPUT | + your request has not been processed due to invalid syntax | + e.g. bad IPv4 like 300.400.abc.256 + e.g. bad decimal like 2a3b4c or bigger than MAX_INT 1;CD;COD;COUNTRY | + contains two-letter (ISO 3166) and three-letter country codes, and a full country name + country name may be multi-word and contain spaces + e.g. we take your IP: | + URL looks like this: https://ip2c.org/128.134.3.161 | or | https://ip2c.org/?ip=128.134.3.161 | + resulting string is: 1;KR;KOR;Korea Republic of 2;;;UNKNOWN | + given ip/dec not found in database or not yet physically assigned to any country The first digit indicates status so you don't have to always parse the whole string. Output is always semicolon delimited text/plain - you can pass it to any type of application.
댓글()