Writing a simple WHOIS client is more cursed than you think.
Seriously though.
I am known for writing cursed JavaScript applets but this one, went above my own charts.
So, lets glance over this curse.
for (const line of dataLines) {
// ignore comments, some use "%", some use "#"
if (line.startsWith("%") || line.startsWith("#")) continue;
// ignore empty lines
if (line.length === 0 || line.match(/^\s+$/)) continue;
// if line starts with one of below
if (line.startsWith("refer:") || line.startsWith("whois:") || line.startsWith("ReferralServer:")) {
// split line by spaces, ignore the first value (which is the value identifier), join spaces and strip beginning and end spaces
let stripped = this.__strStrip(line.split(" ").slice(1).join(" "));
// push the stripped one
whoisServersRaw.push(stripped);
}
// uh, if this is a domain whois result, do some regex magic I cba explaining this
if (this.__strStrip(line).match(/^\w+ WHOIS Server: /i)) {
let strippassone = this.__strStrip(line).replace(/^\w+ WHOIS Server: /i, "");
whoisServersRaw.push(strippassone);
}
}
// well, rwhois not really whois
for (const server of whoisServersRaw) {
if (server.startsWith("rwhois://") || server.includes(":4321")) continue;
whoisServers.push(server.replace("whois://", ""));
}
WHOIS is a big free for all. Parsing the output for recursive WHOIS is not only important, but a whole other craftwork.
Now, that was referral parsing but uh; how do you even get the right encoded data?
Right, WHOIS doesn't specify an encoding. Luckily, whois(1) comes to rescue. So this became a thing:
let encoding = (this.__extQuirks[host] ? this.__extQuirks[host].encoding : chardet.detect(data));
return resolve(iconv.decode(data, encoding));
Then there's the conversion of event-driven Node.js TCP stack to async-await style calls.
Then, there was the simple web app. Well that was easier than the WHOIS client.
w.iye.be is a test instance for the code for new-iwhois.
The code is available at GitHub.
Copyright 2018-2024, linuxgemini (İlteriş Yağıztegin Eroğlu). Any and all opinions listed here are my own and not representative of my employers; future, past and present.