通過 Gandi API 查詢域名


直接記錄測試用的代碼.

package.json

1
2
3
4
5
{
"dependencies": {
"xmlrpc": "^1.3.0"
}
}

index.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
var xmlrpc = require('xmlrpc');
var apikey = '____YOUR____API___KEY___';
var words = ['cut', 'daily', 'dance', 'danger', 'dark', 'date', 'day', 'dead', 'deal', 'death', 'decide', 'decision', 'declare', 'deep', 'defense', 'degree', 'demand', 'department', 'depend', 'dependent', 'describe', 'desire', 'destroy', 'detail', 'determine', 'develop', 'die', 'difference', 'different', 'difficult', 'difficulty', 'dinner', 'direct', 'direction', 'director', 'discover', 'discuss', 'discussion', '___YOUR___WORDS___ETC___'];

var api = xmlrpc.createSecureClient({
host: 'rpc.ote.gandi.net', // 'rpc.gandi.net' for production
port: 443,
path: '/xmlrpc/'
});

api.methodCall('version.info', [apikey], function (error, value) {
console.dir(value);
});

function run(domain) {
var callback = function(error, value) {
console.log(new Date().toLocaleString());

if (value[domain] == 'pending') {
setTimeout(function() {
api.methodCall('domain.available', [apikey, [domain]], callback);
}, 700);
}else if (value[domain] == 'error_invalid') {
console.dir("Err - " + domain);
}else{
console.dir(value)
}
}

api.methodCall('domain.available', [apikey, [domain]], callback)
}

// Make sure the word length bigger than 2
// words = words.filter(function(word) {
// return word.length > 2;
// });

words.some(function(word) {
run(word + ".xyz");
});