@mitrajit/simple-whois 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/whois.js ADDED
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ /*
3
+ * decaffeinate suggestions:
4
+ * DS101: Remove unnecessary use of Array.from
5
+ * DS102: Remove unnecessary code created because of implicit returns
6
+ * DS205: Consider reworking code to avoid use of IIFEs
7
+ * DS207: Consider shorter variations of null checks
8
+ * DS208: Avoid top-level this
9
+ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
10
+ */
11
+ const _ = require("underscore");
12
+ const net = require("net");
13
+ const socks = require("socks").SocksClient;
14
+ const punycode = require("punycode");
15
+ const util = require("util");
16
+ this.SERVERS = require("./servers.json");
17
+ this.lookup = (addr, options, done) => {
18
+ let parts;
19
+ if (typeof done === "undefined" && typeof options === "function") {
20
+ done = options;
21
+ options = {};
22
+ }
23
+ _.defaults(options, {
24
+ follow: 2,
25
+ timeout: 60000,
26
+ }); // 60 seconds in ms
27
+ done = _.once(done);
28
+ let { server } = options;
29
+ let { proxy } = options;
30
+ const { timeout } = options;
31
+ if (!server) {
32
+ switch (true) {
33
+ case _.contains(addr, "@"):
34
+ done(new Error("lookup: email addresses not supported"));
35
+ return;
36
+ break;
37
+ case net.isIP(addr) !== 0:
38
+ server = this.SERVERS["_"]["ip"];
39
+ break;
40
+ default:
41
+ var tld = punycode.toASCII(addr);
42
+ while (true) {
43
+ server = this.SERVERS[tld];
44
+ if (!tld || server) {
45
+ break;
46
+ }
47
+ tld = tld.replace(/^.+?(\.|$)/, "");
48
+ }
49
+ }
50
+ }
51
+ if (!server) {
52
+ done(new Error("lookup: no whois server is known for this kind of object"));
53
+ return;
54
+ }
55
+ if (typeof server === "string") {
56
+ parts = server.split(":");
57
+ server = {
58
+ host: parts[0],
59
+ port: parts[1],
60
+ };
61
+ }
62
+ if (typeof proxy === "string") {
63
+ proxy = proxy.replace("@", ":").replace("//", "");
64
+ parts = proxy.split(":");
65
+ proxy = {
66
+ userId: parts[1],
67
+ password: parts[2],
68
+ host: parts[3],
69
+ port: parseInt(parts[4]),
70
+ };
71
+ }
72
+ _.defaults(server, {
73
+ port: 43,
74
+ query: "$addr\r\n",
75
+ });
76
+ if (proxy) {
77
+ _.defaults(proxy, { type: 5 });
78
+ }
79
+ const _lookup = (socket, done) => {
80
+ let idn = addr;
81
+ if (server.punycode !== false && options.punycode !== false) {
82
+ idn = punycode.toASCII(addr);
83
+ }
84
+ socket.write(server.query.replace("$addr", idn));
85
+ let data = "";
86
+ socket.on("data", (chunk) => {
87
+ return (data += chunk);
88
+ });
89
+ socket.on("timeout", () => {
90
+ socket.destroy();
91
+ return done(new Error("lookup: timeout"));
92
+ });
93
+ socket.on("error", (err) => {
94
+ return done(err);
95
+ });
96
+ return socket.on("close", (err) => {
97
+ if (options.follow > 0) {
98
+ const match = data
99
+ .replace(/\r/gm, "")
100
+ .match(/(ReferralServer|Registrar Whois|Whois Server|WHOIS Server|Registrar WHOIS Server):{1,2}[^\S\n]*((?:r?whois|https?):\/\/)?(.*)/);
101
+ if (match != null && match[3] !== server.host) {
102
+ options = _.extend({}, options, {
103
+ follow: options.follow - 1,
104
+ server: match[3].trim(),
105
+ });
106
+ this.lookup(addr, options, (err, parts) => {
107
+ if (err != null) {
108
+ return done(err);
109
+ }
110
+ if (options.verbose) {
111
+ return done(null, [
112
+ {
113
+ server: server.trim(),
114
+ data,
115
+ },
116
+ ].concat(parts));
117
+ }
118
+ else {
119
+ return done(null, parts);
120
+ }
121
+ });
122
+ return;
123
+ }
124
+ }
125
+ if (options.verbose) {
126
+ return done(null, [
127
+ {
128
+ server: server.trim(),
129
+ data,
130
+ },
131
+ ]);
132
+ }
133
+ else {
134
+ return done(null, data);
135
+ }
136
+ });
137
+ };
138
+ if (proxy) {
139
+ return socks.createConnection({
140
+ proxy,
141
+ destination: {
142
+ host: server.host,
143
+ port: server.port,
144
+ // type: server.type,
145
+ },
146
+ command: "connect",
147
+ timeout: timeout,
148
+ }, (err, info) => {
149
+ if (err != null) {
150
+ return done(err);
151
+ }
152
+ if (timeout) {
153
+ info.socket.setTimeout(timeout);
154
+ }
155
+ _lookup(info.socket, done);
156
+ return info.socket.resume();
157
+ });
158
+ }
159
+ else {
160
+ const sockOpts = {
161
+ host: server.host,
162
+ port: server.port,
163
+ };
164
+ if (options.bind) {
165
+ sockOpts.localAddress = options.bind;
166
+ }
167
+ try {
168
+ const socket = net.connect(sockOpts);
169
+ if (timeout) {
170
+ socket.setTimeout(timeout);
171
+ }
172
+ return _lookup(socket, done);
173
+ }
174
+ catch (conErr) {
175
+ return done(conErr);
176
+ }
177
+ }
178
+ };
179
+ if (module === require.main) {
180
+ const optimist = require("optimist")
181
+ .usage("$0 [options] address")
182
+ .default("s", null)
183
+ .alias("s", "server")
184
+ .describe("s", "whois server")
185
+ .default("f", 0)
186
+ .alias("f", "follow")
187
+ .describe("f", "number of times to follow redirects")
188
+ .default("p", null)
189
+ .alias("p", "proxy")
190
+ .describe("p", "SOCKS proxy")
191
+ .boolean("v")
192
+ .default("v", false)
193
+ .alias("v", "verbose")
194
+ .describe("v", "show verbose results")
195
+ .default("b", null)
196
+ .alias("b", "bind")
197
+ .describe("b", "bind to a local IP address")
198
+ .boolean("h")
199
+ .default("h", false)
200
+ .alias("h", "help")
201
+ .describe("h", "display this help message");
202
+ if (optimist.argv.h) {
203
+ console.log(optimist.help());
204
+ process.exit(0);
205
+ }
206
+ if (optimist.argv._[0] == null) {
207
+ console.log(optimist.help());
208
+ process.exit(1);
209
+ }
210
+ this.lookup(optimist.argv._[0], {
211
+ server: optimist.argv.server,
212
+ follow: optimist.argv.follow,
213
+ proxy: optimist.argv.proxy,
214
+ verbose: optimist.argv.verbose,
215
+ bind: optimist.argv.bind,
216
+ }, (err, data) => {
217
+ if (err != null) {
218
+ console.log(err);
219
+ process.exit(1);
220
+ }
221
+ if (util.isArray(data)) {
222
+ return (() => {
223
+ const result = [];
224
+ for (let part of Array.from(data)) {
225
+ console.log(part.server.host);
226
+ console.log(part.data);
227
+ result.push(console.log);
228
+ }
229
+ return result;
230
+ })();
231
+ }
232
+ else {
233
+ return console.log(data);
234
+ }
235
+ });
236
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@mitrajit/simple-whois",
3
+ "version": "0.0.1",
4
+ "description": "Package to check the whois data by the domain name",
5
+ "keywords": [
6
+ "whois",
7
+ "whois-parser",
8
+ "domain",
9
+ "tld",
10
+ "domain-whois",
11
+ "domain-tld"
12
+ ],
13
+ "homepage": "https://github.com/Mitrajit/simple-whois#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/Mitrajit/simple-whois/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Mitrajit/simple-whois.git"
20
+ },
21
+ "license": "MIT",
22
+ "author": "Mitrajit",
23
+ "type": "commonjs",
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "prepare": "npm run build",
32
+ "publish": "npm publish --access public"
33
+ },
34
+ "devDependencies": {
35
+ "typescript": "^4.9.5"
36
+ },
37
+ "dependencies": {
38
+ "punycode": "^2.3.1"
39
+ }
40
+ }