23 lines
640 B
JavaScript
23 lines
640 B
JavaScript
var http = require('http');
|
|
var libqqwry = require('lib-qqwry');
|
|
var qqwry = libqqwry() //初始化IP库解析器
|
|
qqwry.speed(); //启用急速模式;
|
|
|
|
function getClientIp(req) {
|
|
return req.headers['x-forwarded-for'] ||
|
|
req.connection.remoteAddress ||
|
|
req.socket.remoteAddress ||
|
|
req.connection.socket.remoteAddress;
|
|
};
|
|
|
|
function getIpLocation(ip) {
|
|
let data = qqwry.searchIP(ip)
|
|
if (!data) {
|
|
return ip;
|
|
}
|
|
let area = data.Area.trim().toLowerCase().replace('cz88.net', '');
|
|
return data.Country + ' ' + area;
|
|
}
|
|
|
|
exports.getClientIp = getClientIp;
|
|
exports.getIpLocation = getIpLocation; |