Compress IPv6 addresses on /tools/rdns

parent 8062a8a3
......@@ -47,6 +47,8 @@ router.get("/whois", (req: Request, res: Response, next: NextFunction) => {
}
});
import compressIp from "../functions/compressIp";
/**
* Reverse DNS lookup
*/
......@@ -54,32 +56,38 @@ router.get("/rdns", (req: Request, res: Response, next: NextFunction) => {
const address = req.query.ip;
if(address && isIp(address)) {
axios.get(`https://api.telcodb.net/v1/rdns?format=json&q=${address}`)
.then((response) => {
// If response.data.addresses not found, return response.data
let resp = response.data.addresses ? response.data.addresses : response.data;
res.render("tools/rdns.twig", {
"title": "Reverse DNS lookup",
"address": address,
"status": response.status,
"result": resp,
});
})
.catch((error) => {
const response = error.response;
// console.error(error);
res.render("tools/rdns.twig", {
"robots": "noindex, noarchive",
"title": "Reverse DNS lookup",
"address": address,
"status": response.status,
"result": "API Error: " + response.data,
const compressedIp = compressIp(address);
if(address !== compressedIp) {
res.redirect(`/tools/rdns?ip=${compressedIp}`);
} else {
axios.get(`https://api.telcodb.net/v1/rdns?format=json&q=${address}`)
.then((response) => {
// If response.data.addresses not found, return response.data
let resp = response.data.addresses ? response.data.addresses : response.data;
res.render("tools/rdns.twig", {
"title": "Reverse DNS lookup",
"address": address,
"status": response.status,
"result": resp,
});
})
.catch((error) => {
const response = error.response;
// console.error(error);
res.render("tools/rdns.twig", {
"robots": "noindex, noarchive",
"title": "Reverse DNS lookup",
"address": address,
"status": response.status,
"result": "API Error: " + response.data,
});
});
})
}
} else {
const result = address ? "Invalid IP address" : null;
const robots = address ? "noindex, noarchive" : null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment