parse whois data dfferent
This commit is contained in:
parent
b857ddba48
commit
a2147eef8c
|
@ -119,6 +119,9 @@ export function getIPv6Subnet(ip) {
|
||||||
* @return [start, end] with numerical IPs (32bit integer)
|
* @return [start, end] with numerical IPs (32bit integer)
|
||||||
*/
|
*/
|
||||||
function ip4RangeStrToRangeNum(range) {
|
function ip4RangeStrToRangeNum(range) {
|
||||||
|
if (!range) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const [start, end] = range.split('-')
|
const [start, end] = range.split('-')
|
||||||
.map(ip4ToNum);
|
.map(ip4ToNum);
|
||||||
if (!start || !end || start > end) {
|
if (!start || !end || start > end) {
|
||||||
|
|
|
@ -18,13 +18,13 @@ function cIDRofWhois(ip, whoisData) {
|
||||||
return whoisData.inet6num
|
return whoisData.inet6num
|
||||||
|| (whoisData.range && !whoisData.range.includes('-') && whoisData.range)
|
|| (whoisData.range && !whoisData.range.includes('-') && whoisData.range)
|
||||||
|| whoisData.route
|
|| whoisData.route
|
||||||
|| 'N/A';
|
|| null;
|
||||||
}
|
}
|
||||||
const { range } = whoisData;
|
const { range } = whoisData;
|
||||||
if (range.includes('/') && !range.includes('-')) {
|
if (range && range.includes('/') && !range.includes('-')) {
|
||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
return ip4InRangeToCIDR(ip, range) || 'N/A';
|
return ip4InRangeToCIDR(ip, range) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -63,7 +63,7 @@ function parseWhois(ip, whoisData) {
|
||||||
return {
|
return {
|
||||||
ip,
|
ip,
|
||||||
country: countryFromWhois(whoisData),
|
country: countryFromWhois(whoisData),
|
||||||
cidr: cIDRofWhois(ip, whoisData),
|
cidr: cIDRofWhois(ip, whoisData) || 'N/A',
|
||||||
org: orgFromWhois(whoisData),
|
org: orgFromWhois(whoisData),
|
||||||
descr: whoisData.descr || 'N/A',
|
descr: whoisData.descr || 'N/A',
|
||||||
asn: whoisData.asn || 'N/A',
|
asn: whoisData.asn || 'N/A',
|
||||||
|
@ -71,7 +71,7 @@ function parseWhois(ip, whoisData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function whois(ip) {
|
async function whois(ip) {
|
||||||
let whoisData = await whoiser.ip(ip);
|
const whoisData = await whoiser.ip(ip);
|
||||||
if (whoisData.ReferralServer) {
|
if (whoisData.ReferralServer) {
|
||||||
let referral = whoisData.ReferralServer;
|
let referral = whoisData.ReferralServer;
|
||||||
const prot = referral.indexOf('://');
|
const prot = referral.indexOf('://');
|
||||||
|
@ -79,9 +79,17 @@ async function whois(ip) {
|
||||||
referral = referral.slice(prot + 3);
|
referral = referral.slice(prot + 3);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
whoisData = await whoiser.ip(ip, {
|
/*
|
||||||
|
* if referral whois server produces any error
|
||||||
|
* fallback to initial one
|
||||||
|
*/
|
||||||
|
const refWhoisData = await whoiser.ip(ip, {
|
||||||
host: referral,
|
host: referral,
|
||||||
});
|
});
|
||||||
|
const refParsedData = parseWhois(ip, refWhoisData);
|
||||||
|
if (refParsedData.cidr !== 'N/A') {
|
||||||
|
return refParsedData;
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// nothing
|
// nothing
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user