npm install iparea
var ipArea = new (require('iparea'))();
1 timeout option, default 1000ms.
var ipArea = new (require('iparea'))({timeout: 1000});
2 url option, using sina API proxy.
default: http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=
var ipArea = new (require('iparea'))({url:'http://127.0.0.1:52000/iplookup/iplookup.php?format=json&ip=', timeout: 2000});
ipArea.getIPArea('127.0.0.1',function(err, data){
console.log(data);
});
inputs && results
// 0.0.0.0
未识别
// 127.0.0.1
本地
// 192.168.1.1
局域网
// 183.129.210.50
浙江
// 66.104.77.20
美国
ipArea.getIPInfo('127.0.0.1',function(err, data){
console.log(data);
});
inputs && results
// 0.0.0.0
-2
// 127.0.0.1
{ ret: -1, ip: '127.0.0.1' }
// 192.168.1.1
{ ret: -1, ip: '192.168.1.1' }
// 183.129.210.50
{ ret: 1,
start: -1,
end: -1,
country: '美国',
province: '',
city: '',
district: '',
isp: '',
type: '',
desc: ''
}
// 66.104.77.20
{ ret: 1,
start: -1,
end: -1,
country: '**',
province: '浙江',
city: '杭州',
district: '',
isp: '',
type: '',
desc: ''
}
Add method: getIPInfo.
Add url option, using sina API proxy.
Add timeout option; Change method-name: getIPAdrea to getIPArea.
Make all return data type to be string.
1 Add return error param; 2 improve http deal.