73 lines
2 KiB
JavaScript
73 lines
2 KiB
JavaScript
const axios = require("axios");
|
|
const cheerio = require("cheerio");
|
|
|
|
let headers = {
|
|
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0",
|
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
"Accept-Language": "en-US,en"
|
|
}
|
|
|
|
module.exports = {
|
|
ip: async function(ip) {
|
|
let url;
|
|
|
|
if (!ip) url = `https://ip.me/`;
|
|
else url = `https://ip.me/ip/${ip}`;
|
|
|
|
let resp = await axios({
|
|
method: "GET",
|
|
url: url,
|
|
headers: headers
|
|
});
|
|
|
|
let $ = cheerio.load(resp.data);
|
|
|
|
let data = {};
|
|
let titles = [];
|
|
|
|
for (let i in $("table > tbody > tr > th")) {
|
|
if (!$("table > tbody > tr > th")[i] || !$("table > tbody > tr > th")[i].children?.[0]) continue;
|
|
|
|
let title = $("table > tbody > tr > th")[i].children[0].data.toLowerCase();
|
|
title = title.substring(0, title.length - 1);
|
|
title = title.split(" ");
|
|
if (title.length > 1) {
|
|
for (let a in title) {
|
|
if (a > 0) {
|
|
title[a] = `${title[a].substring(0, 1).toUpperCase()}${title[a].substring(1)}`;
|
|
}
|
|
}
|
|
}
|
|
title = title.join("");
|
|
titles.push(title);
|
|
}
|
|
|
|
for (let i in $("table > tbody > tr > td > code")) {
|
|
if (!$("table > tbody > tr > td > code")[i] || !$("table > tbody > tr > td > code")[i].children?.[0]) continue;
|
|
|
|
let dat = $("table > tbody > tr > td > code")[i].children[0].data;
|
|
let title = titles[i];
|
|
if (dat == "None") dat = undefined;
|
|
data[title] = dat;
|
|
}
|
|
|
|
return data;
|
|
},
|
|
whois: async function(domain) {
|
|
if (!domain) throw new Error("Parameter required: domain");
|
|
|
|
if (domain.startsWith("http:") || domain.startsWith("https:")) domain = new URL(domain).hostname;
|
|
|
|
let url = `https://ip.me/whois/${domain}`;
|
|
let resp = await axios({
|
|
method: "GET",
|
|
url: url,
|
|
headers: headers
|
|
});
|
|
|
|
let $ = cheerio.load(resp.data);
|
|
|
|
let text = $("pre").text().split(`\t`).join(``).split(`\r`).join(``);
|
|
return text;
|
|
}
|
|
} |