Created
June 26, 2019 21:20
-
-
Save mariohmol/b8a523401277fb91c9a16c6ca1f456b1 to your computer and use it in GitHub Desktop.
node whois example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var whois = require('node-whois') | |
var sys = require('sys') | |
var exec = require('child_process').exec; | |
require('dotenv').config(); | |
const dns = require('dns'); | |
const apiKey = process.env.nodeWhoisApiKey || "123456"; | |
let protection=0; | |
const maxProtection=200; | |
var express = require('express') | |
var app = express() | |
app.get('/', function (req, res) { | |
if(req.query.apikey!=apiKey) return res.sendStatus(403); | |
protection++; | |
if(protection>maxProtection) return res.sendStatus(404); | |
let domain = req.query.domain; | |
let count=0; | |
let returned = {}; | |
whois.lookup(domain, function(err, data) { | |
returned.whois = data; | |
dns.lookup(domain, { family: 4 }, (error, ip, family) => { | |
if (error) { | |
return res.sendStatus(404); | |
} | |
returned.ip=ip; | |
return res.json(returned); | |
}); | |
}); | |
}); | |
app.listen(3001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment