-1
I am trying to make a tool just for my personal use, it is a WHOIS/ DNS search tool, and I use the API of another site to do this.
The URL I’m using to make the request is: http://www.isptools.com.br/tool.whois_json.php?query=
And you can put whatever you want after the URL that will be consulted.
My program collects the data successfully, but it sends back the "res" before the whois information is back, so the variable is Undefined.
function whois(ip) {
var content;
fetch('http://www.isptools.com.br/tool.whois_json.php?query='+ip)
.then(res => res.json())
.then(data => content = data)
.then((content) => {
console.log(content); // returns the actual data
return content; // I have two of these just for testing purposes
})
return content; // :)
}
app.get("/query/:type/:ip",(req,res) => {
var type = req.params.type;
var ip = req.params.ip;
var dados = 'nada';
if (type === 'whois') {
try {
dados = whois(ip);
} catch(err){
console.log("Um erro ocorreu ao tentar fazer um query de WHOIS:\n"+err);
}
}
console.log(dados); //returns undefined.
res.send(dados); // returns a blank html
});
How can I do this the right way? I have no idea.
Thank you very much!
I’m Sorry if I Did Something Wrong on the posting part or Something Idiot on the code... Why I’m Betting down voted?
– Blantyre
In [en.so] you should ask at Português
– Woss
makes perfect sense, sorry... I had not seen that I was in Brazilian... I changed the language of the question
– Blantyre