-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathip2Location.js
More file actions
44 lines (37 loc) · 1.01 KB
/
ip2Location.js
File metadata and controls
44 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module.exports.ip2Location = function (ipAddress,callback) {
var https = require('https');
var http = require('http');
var str = '';
//ipAddress = "0.0.0.0";
var options = {
host: 'ip-api.com',
port: 80,
path: '/json/'+ipAddress,
method: 'POST'
};
var req = http.get(options, function (res) {
res.on('data', function (body) {
str += body;
});
res.on('end', function () {
if(JSON.parse(str).status == "fail"){
return callback(str,null);
}
return callback(null,str);
});
}).on('error', function (err) {
return callback(err,null);
});
req.end();
}
/*
url2 = "http://geoip.nekudo.com/api/223.230.36.72";
url1 = "http://freegeoip.net/json/8.8.8.8";
url = "http://ip-api.com/json/223.230.36.72"
var options1 = {
host: 'geoip.nekudo.com',
port: 80,
path: '/api/8.8.8.8',
method: 'POST'
};
*/