kefu/utils/common.js
2019-09-30 10:31:42 +08:00

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;