-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgimme.js
executable file
·71 lines (67 loc) · 2.01 KB
/
gimme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env node
/**
* gimme
* cut through the cruft of whois, find availability info quickly
* usage: $ gimme example
* uses twitter.com and instantdomainsearch.com for data
* Dan Motzenbecker
* MIT License
*/
var input = process.argv[2];
if(typeof input === 'undefined'){
console.log('Try feeding me a name...like:\n$ gimme example');
return;
}
var exts = ['com', 'net', 'org', 'biz', 'mobi'],
domain = /^[\w-]+/.exec(input),
ext = /\.\w+$/.exec(input);
if(ext !== null){
ext = ext.toString().replace('.', '');
if(exts.indexOf(ext) === -1){
var str = 'Sorry, gimme only works with \x1b[36m';
for(var i = 0, len = exts.length; i < len; i++){
str += '.' + exts[i] + ' ';
}
str += '\x1b[0mand \x1b[36mtwitter\x1b[0m right now. '
+ '\n\nHere\'s what gimme found anyway:';
console.log(str);
}
}
var http = require('http'),
dParams = {
host : 'instantdomainsearch.com',
port : 80,
path : '/services/quick/?name=' + domain
},
tParams = {
host : 'twitter.com',
port : 80,
path : '/' + domain
};
http.get(dParams, function(res){
var data = '';
res.on('data', function(chunk){
data += chunk;
});
res.on('end', function(){
try{
var obj = JSON.parse(data);
}catch(e){
console.log(' \x1b[31msomething went wrong checking the domain status...\x1b[0m\n');
return;
}
for(var i = 0, len = exts.length; i < len; i++){
var status = (obj[exts[i]] === 'a') ? 'YES ' : ' NO ',
color = (status === 'YES ') ? '\x1b[32m' : '\x1b[31m',
str = color + status + domain + '.' + exts[i] + '\x1b[0m';
console.log(str);
}
});
});
http.get(tParams, function(res){
if(res.statusCode === 200){
console.log('\x1b[31m NO twitter.com/' + domain + '\x1b[0m');
}else{
console.log('\x1b[32mYES twitter.com/' + domain + '\x1b[0m');
}
});