geoip lookup
1.0.0
geoip-lookup
2개의 간단한 API인 .lookup
및 .match
노출합니다. 둘 다 비동기식이지만 .match
정보를 검색할 때까지 콜백을 "차단"합니다.
.lookup
데이터가 검색된 후 업데이트되는 LevelUp 로컬 데이터베이스에 데이터가 캐시되지 않은 경우 정의되지 않은 결과를 반환합니다.
용법:
var geoip = require('geoip-lookup');
// This will attempt to check the local database. if not found, it will return an empty result (non-blocking), but will cache the data later
// when the lookup is complete. Useful when e.g. part of an express middleware which you don't want to block rendering the page when your
// next() call is in the callback.
geoip.lookup('10.10.1.1', function(err, result) {
if (err) {
console.error(err.stack);
} else if (result) {
console.log(result);
} else {
console.log('result not found in local database');
}
next();
});
// This will get the information from MaxMind and only invoke the callback when it is retrieved.
// it will effectively "block" via the callback, and probably not suitable if continuous execution depends on callbacks
geoip.check('10.10.1.1', function(err, result) {
if (err) {
console.error(err.stack);
} else {
console.log(result);
}
}
기본적으로 히트
freegeoip.net/json/<ip address>
자세한 내용은 https://freegeoip.net/을 참조하세요.
형식으로 JSON을 반환합니다.
{
city: "Willemstad"
country_code: "CW"
country_name: "Curaçao"
ip: "190.88.211.185"
latitude: 12.1
longitude: -68.917
metro_code: 0
region_code: ""
region_name: ""
time_zone: "America/Curacao"
zip_code: ""
}
LevelDB를 통해 IP 주소 캐시/위치 조회를 시도하고, 그렇지 않으면 MaxMind에서 제공하는 "데모" RESTful API를 통해 데이터를 가져옵니다.
대규모로 수행하는 경우 이를 수행하려면 적절한 라이센스를 받아야 하기 때문에 이것이 "합법적"인지는 확실하지 않습니다.
기본적으로 히트
https://www.maxmind.com/geoip/v2.1/city/<ip address>?demo=1
다음 형식으로 JSON을 반환합니다.
{
"country":{
"iso_code":"US",
"names":{
"pt-BR":"Estados Unidos",
"es":"Estados Unidos",
"ru":"Сша",
"en":"United States",
"zh-CN":"美国",
"fr":"États-Unis",
"de":"USA",
"ja":"アメリカ合衆国"
},
"geoname_id":6252001
},
"location":{
"longitude":-121.895,
"latitude":37.3394,
"time_zone":"America/Los_Angeles",
"metro_code":807
},
"subdivisions":[
{
"iso_code":"CA",
"names":{
"pt-BR":"Califórnia",
"es":"California",
"ru":"Калифорния",
"en":"California",
"zh-CN":"加利福尼亚州",
"fr":"Californie",
"de":"Kalifornien",
"ja":"カリフォルニア州"
},
"geoname_id":5332921
}
],
"city":{
"names":{
"en":"San Jose",
"fr":"San José",
"pt-BR":"San José",
"de":"San José",
"ja":"サンノゼ",
"es":"San José",
"ru":"Сан-Хосе"
},
"geoname_id":5392171
},
"continent":{
"names":{
"pt-BR":"América do Norte",
"es":"Norteamérica",
"ru":"Северная Америка",
"en":"North America",
"zh-CN":"北美洲",
"fr":"Amérique du Nord",
"de":"Nordamerika",
"ja":"北アメリカ"
},
"geoname_id":6255149,
"code":"NA"
},
"maxmind":{
"queries_remaining":24
},
"registered_country":{
"iso_code":"US",
"names":{
"pt-BR":"Estados Unidos",
"es":"Estados Unidos",
"ru":"Сша",
"en":"United States",
"zh-CN":"美国",
"fr":"États-Unis",
"de":"USA",
"ja":"アメリカ合衆国"
},
"geoname_id":6252001
},
"traits":{
"autonomous_system_number":<some integer>,
"ip_address":"<ip address>",
"organization":"<some organization>",
"isp":"<some ISP>",
"autonomous_system_organization":"<some system organization>"
}
}