Skip to content

Commit 046e240

Browse files
committed
More samples, .net fixes.
1 parent 14a313f commit 046e240

14 files changed

Lines changed: 404 additions & 70 deletions

File tree

bulk/node/bulk.search.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var fs = require('fs'), https = require('https');
2+
3+
var dom = ['google.com', 'youtube.com', 'facebook.com', 'whoisxmlapi.com'];
4+
var srv = 'www.whoisxmlapi.com', url = '/BulkWhoisLookup/bulkServices/';
5+
var pass = 'PASSWORD', username = 'ACCOUNT USERNAME', file = 'bulk.csv';
6+
7+
function api(path, data, callback) {
8+
var baseData = {password: pass, username: username, outputFormat: 'json'};
9+
var header = {'Content-Type': 'application/json'}, body = '';
10+
var opts = {host: srv, path: url + path, method:'POST', headers: header};
11+
https.request(opts, function(response) {
12+
response.on('data', function(chunk) { body += chunk; });
13+
response.on('end', function() { callback(body); });
14+
}).end(JSON.stringify(Object.assign({}, baseData, data)));
15+
}
16+
// This will save whois record info for all domains as 'bulk.csv' in curr. dir
17+
api('bulkWhois', {domains:dom}, function(body) {
18+
var id = {requestId:JSON.parse(body).requestId, startIndex: dom.length+1};
19+
var timer = setInterval(function() {
20+
api('getRecords', Object.assign({},id,{maxRecords:0}),function(body) {
21+
if (JSON.parse(body).recordsLeft) { return; }
22+
clearInterval(timer);
23+
if (typeof JSON.parse(body).recordsLeft==='undefined') { return; }
24+
api('download', id, function(csv) { fs.writeFile(file,csv); });
25+
});
26+
}, 3000);
27+
});

bulk/python/bulkwhois.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import requests
2+
import logging
3+
import json
4+
import time
5+
from argparse import ArgumentParser
6+
7+
"""
8+
sample:
9+
./bulkwhois.py -u test -p user -d yandex.ru whoisxmlapi.com --output bulk
10+
"""
11+
12+
# Preparing arguments
13+
argparser = ArgumentParser(description='BulkWhois querry')
14+
argparser.add_argument('-u', '--username', help='user name for auth', type=str, required=True)
15+
argparser.add_argument('-p', '--password', help='password', type=str, required=True)
16+
argparser.add_argument('-d', '--domains', help='list of domains separated by spaces',
17+
type=str, nargs='+', required=True)
18+
argparser.add_argument('--interval', help='requesting interval', type=int, default=15)
19+
argparser.add_argument('--format', help='data format', type=str, choices=['json', 'xml'], default='json')
20+
argparser.add_argument('--output', help='output name without extension', type=str, required=True)
21+
args = argparser.parse_args()
22+
23+
logging.basicConfig(
24+
format='%(asctime)s [%(levelname)s] %(message)s',
25+
level=logging.DEBUG
26+
)
27+
28+
bulkwhois_base_url = 'https://www.whoisxmlapi.com/BulkWhoisLookup/bulkServices/'
29+
session = requests.session()
30+
31+
data = {
32+
"domains": args.domains,
33+
"password": args.password,
34+
"username": args.username,
35+
"outputFormat": args.format
36+
}
37+
38+
header = {'Content-Type': 'application/json'}
39+
if args.format == 'xml':
40+
header = {'Content-Type': 'application/xml'}
41+
42+
logging.debug("data:" + str(data))
43+
logging.debug("headers:" + str(header))
44+
45+
# Posting task to API
46+
response = session.post(bulkwhois_base_url + 'bulkWhois',
47+
data=json.dumps(data),
48+
headers=header,
49+
timeout=5)
50+
if response.status_code != 200:
51+
logging.error("wrong response code: %i" % response.status_code)
52+
exit(1)
53+
response_data = json.loads(response.text)
54+
if response_data['messageCode'] == 200:
55+
logging.debug('Response: ' + response.text)
56+
del data['domains']
57+
data.update({
58+
'requestId': response_data['requestId'],
59+
'searchType': 'all',
60+
'maxRecords': 1,
61+
'startIndex': 1
62+
})
63+
else:
64+
logging.error('Response: ' + response.text)
65+
exit(1)
66+
67+
# waiting for job complete
68+
logging.debug("data:" + str(data))
69+
recordsLeft = len(args.domains)
70+
while recordsLeft > 0:
71+
time.sleep(args.interval)
72+
response = session.post(bulkwhois_base_url + 'getRecords',
73+
headers=header,
74+
data=json.dumps(data))
75+
if response.status_code != 200:
76+
logging.error("wrong response code: %i" % response.status_code)
77+
exit(1)
78+
recordsLeft = json.loads(response.text)['recordsLeft']
79+
logging.debug('Response: ' + response.text)
80+
81+
data.update({'maxRecords': len(args.domains)})
82+
# dump json data
83+
time.sleep(args.interval)
84+
response = session.post(bulkwhois_base_url + 'getRecords',
85+
headers=header,
86+
data=json.dumps(data))
87+
with open(args.output + '.json','w') as json_file:
88+
json.dump(json.loads(response.text),json_file)
89+
90+
# download csv data
91+
time.sleep(args.interval)
92+
with open(args.output + '.csv', 'wt') as csv_file:
93+
response = session.post(bulkwhois_base_url + 'download',
94+
headers=header,
95+
data=json.dumps(data))
96+
for line in response.text.split('\n'):
97+
clear_line = line.strip()
98+
# remove blank lines
99+
if clear_line != '':
100+
csv_file.write(clear_line + '\n')

dnsApi/node/dnsApi.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var http = require('http');
2+
3+
var domain = 'example.com';
4+
var password = 'your_whois_api_password';
5+
var username = 'your_whois_api_username';
6+
7+
var url = 'http://www.whoisxmlapi.com/whoisserver/DNSService?type=_all'
8+
+ '&domainName=' +domain +'&username='+username+'&password='+password;
9+
10+
http.get(url, function(response) {
11+
var str = '';
12+
response.on('data', function(chunk) { str += chunk; });
13+
response.on('end', function() { console.log(str); });
14+
}).end();

dnsApi/php/dnsApi.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
$domain = 'example.com';
4+
$password = 'your_whois_api_password';
5+
$username = 'your_whois_api_username';
6+
7+
$url ="http://www.whoisxmlapi.com/whoisserver/DNSService?domainName={$domain}"
8+
."&username={$username}&password={$password}&type=_all";
9+
10+
print(file_get_contents($url));

dnsApi/python/dnsApi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
try:
2+
from urllib.request import urlopen
3+
except ImportError:
4+
from urllib2 import urlopen
5+
6+
domain = 'example.com'
7+
password = 'your_whois_api_password'
8+
username = 'your_whois_api_username'
9+
10+
url = 'http://www.whoisxmlapi.com/whoisserver/DNSService?type=_all'\
11+
+ '&domainName=' +domain + '&username=' +username + '&password=' +password
12+
13+
print(urlopen(url).read().decode('utf8'))

emailApi/node/emailApi.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var http = require('http');
2+
3+
var email = 'support@whoisxmlapi.com';
4+
var password = 'your_whois_api_password';
5+
var username = 'your_whois_api_username';
6+
7+
var url = 'http://www.whoisxmlapi.com/whoisserver/EmailVerifyService'
8+
+ '?emailAddress=' + email
9+
+ '&validateDNS=true&validateSMTP=true&checkCatchAll=true'
10+
+ '&checkFree=true&checkDisposable=true'
11+
+ '&username=' + username + '&password=' + password
12+
13+
http.get(url, function(response) {
14+
var str = '';
15+
response.on('data', function(chunk) { str += chunk; });
16+
response.on('end', function() { console.log(str); });
17+
}).end();

emailApi/php/emailApi.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$emailAddress = 'support@whoisxmlapi.com';
4+
$password = 'your_whois_api_password';
5+
$username = 'your_whois_api_username';
6+
7+
$url = "http://www.whoisxmlapi.com/whoisserver/EmailVerifyService"
8+
. "?emailAddress={$emailAddress}&validateDNS=true&validateSMTP=true"
9+
. "&checkCatchAll=true&&checkFree=true&checkDisposable=true"
10+
. "&username={$username}&password={$password}";
11+
12+
print(file_get_contents($url));

emailApi/python/emailApi.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
try:
2+
from urllib.request import urlopen
3+
except ImportError:
4+
from urllib2 import urlopen
5+
6+
emailAddress = 'support@whoisxmlapi.com';
7+
password = 'your_whois_api_password'
8+
username = 'your_whois_api_username'
9+
10+
url = 'http://www.whoisxmlapi.com/whoisserver/EmailVerifyService?'\
11+
+ 'emailAddress=' + emailAddress + '&validateDNS=true&validateSMTP=true'\
12+
+ '&checkCatchAll=true&checkFree=true&checkDisposable=true'\
13+
+ '&username=' + username + '&password=' + password
14+
15+
print(urlopen(url).read().decode('utf8'))

password/net/visualStudio/Whois/whois.cs

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ static void Main(string[] args)
2020
//////////////////////////
2121
// Fill in your details //
2222
//////////////////////////
23-
string username = "YOUR_USERNAME";
24-
string password = "YOUR_PASSWORD";
23+
string username = "username";
24+
string password = "xxxxxxxxxx";
2525
string domain = "google.com";
2626

2727
/////////////////////////
@@ -152,19 +152,33 @@ public void PrintPairs()
152152
{
153153
try
154154
{
155-
s = ((string)subpair.Value).Replace("\n", "");
155+
string valType = subpair.Value.GetType().ToString();
156+
s = valType.Equals("System.Int32")
157+
? subpair.Value.ToString()
158+
: ((string)subpair.Value).Replace("\n", "");
156159
s = "\t" + subpair.Key + ": " + s.Substring(0, (s.Length < 40 ? s.Length : 40)) + "\n";
157160
Console.Write(s);
158161
}
159162
catch (Exception e2)
160163
{
161164
Console.Write("\t" + subpair.Key + ":\n");
162165

163-
foreach (var subsubpair in subpair.Value as System.Collections.Generic.Dictionary<string, object>)
166+
try
164167
{
165-
s = subsubpair.Value.ToString().Replace("\n", "");
166-
s = "\t\t" + subsubpair.Key + ": " + s.Substring(0, (s.Length < 40 ? s.Length : 40)) + "\n";
167-
Console.Write(s);
168+
foreach (var subsubpair in subpair.Value as System.Collections.Generic.Dictionary<string, object>)
169+
{
170+
s = subsubpair.Value.ToString().Replace("\n", "");
171+
if (subsubpair.Value.GetType().ToString().Equals("System.Collections.ArrayList")) {
172+
foreach (var value in (ArrayList)subsubpair.Value)
173+
Console.Write("\t\t" + value.ToString() + "\n");
174+
continue;
175+
}
176+
s = "\t\t" + subsubpair.Key + ": " + s.Substring(0, (s.Length < 40 ? s.Length : 40)) + "\n";
177+
Console.Write(s);
178+
}
179+
}
180+
catch (Exception e3) {
181+
Console.Write(subpair.Value + "\n");
168182
}
169183
}
170184
}
@@ -258,32 +272,36 @@ public void PrintToConsole()
258272
{
259273
Console.WriteLine("WhoisRecord:");
260274
Console.WriteLine("\tcreatedDate: " + createdDate);
261-
Console.WriteLine("\texpdatedDate: " + updatedDate);
275+
Console.WriteLine("\tupdatedDate: " + updatedDate);
262276
Console.WriteLine("\texpiresDate: " + expiresDate);
263277
Console.WriteLine("\tregistrant:");
264-
registrant.PrintToConsole();
278+
registrant?.PrintToConsole();
265279
Console.WriteLine("\tadministrativeContact:");
266-
administrativeContact.PrintToConsole();
280+
administrativeContact?.PrintToConsole();
267281
Console.WriteLine("\tbillingContact:");
268-
billingContact.PrintToConsole();
282+
billingContact?.PrintToConsole();
269283
Console.WriteLine("\ttechnicalContact:");
270-
technicalContact.PrintToConsole();
284+
technicalContact?.PrintToConsole();
271285
Console.WriteLine("\ttechnicalContact:");
272-
technicalContact.PrintToConsole();
286+
technicalContact?.PrintToConsole();
273287
Console.WriteLine("\tzoneContact:");
274-
zoneContact.PrintToConsole();
288+
zoneContact?.PrintToConsole();
275289
Console.WriteLine("\tdomainName: " + domainName);
276290
Console.WriteLine("\tnameServers:");
277-
nameServers.PrintToConsole();
278-
Console.WriteLine("\trawText: " + rawText.Substring(0, rawText.Length < 40 ? rawText.Length : 40).Replace("\n", ""));
279-
Console.WriteLine("\theader: " + header.Substring(0, header.Length < 40 ? header.Length : 40).Replace("\n", ""));
280-
Console.WriteLine("\tstrippedText: " + strippedText.Substring(0, strippedText.Length < 40 ? strippedText.Length : 40).Replace("\n", ""));
281-
Console.WriteLine("\tfooter: " + footer.Substring(0, footer.Length < 40 ? footer.Length : 40).Replace("\n", ""));
291+
nameServers?.PrintToConsole();
292+
string str = rawText ?? "";
293+
Console.WriteLine("\trawText: " + str.Substring(0, str.Length < 40 ? str.Length : 40).Replace("\n", ""));
294+
str = header ?? "";
295+
Console.WriteLine("\theader: " + str.Substring(0, str.Length < 40 ? str.Length : 40).Replace("\n", ""));
296+
str = strippedText ?? "";
297+
Console.WriteLine("\tstrippedText: " + str.Substring(0, str.Length < 40 ? str.Length : 40).Replace("\n", ""));
298+
str = footer ?? "";
299+
Console.WriteLine("\tfooter: " + str.Substring(0, str.Length < 40 ? str.Length : 40).Replace("\n", ""));
282300
Console.WriteLine("\taudit:");
283-
audit.PrintToConsole();
301+
audit?.PrintToConsole();
284302
Console.WriteLine("\tregistrarName: " + registrarName);
285303
Console.WriteLine("\tregistryData:");
286-
registryData.PrintToConsole();
304+
registryData?.PrintToConsole();
287305
Console.WriteLine("\tdomainAvailability: " + domainAvailability);
288306
Console.WriteLine("\tcontactEmail: " + contactEmail);
289307
Console.WriteLine("\tdomainNameExt: " + domainNameExt);
@@ -340,23 +358,33 @@ public class WhoisRecordNameServers
340358
{
341359
[System.Xml.Serialization.XmlElement("rawText")]
342360
public string rawText { get; set; }
343-
[System.Xml.Serialization.XmlElement("Address")]
344-
public List<string> hostNames { get; set; }
345-
[System.Xml.Serialization.XmlElement("class")]
346-
public List<string> ips { get; set; }
361+
[System.Xml.Serialization.XmlElement("hostNames")]
362+
public WhoisHosts hostNames { get; set; }
363+
[System.Xml.Serialization.XmlElement("ips")]
364+
public WhoisHosts ips { get; set; }
347365

348366
public void PrintToConsole()
349367
{
350-
Console.WriteLine("\t\trawText: " + rawText.Substring(0, (rawText.Length < 40 ? rawText.Length : 40)).Replace("\n", ""));
368+
string str = rawText ?? "";
369+
Console.WriteLine("\t\trawText: " + str.Substring(0, (str.Length < 40 ? str.Length : 40)).Replace("\n", ""));
370+
351371
Console.WriteLine("\t\thostNames:");
352-
foreach (string hostname in hostNames)
372+
foreach (string hostname in hostNames?.Items)
353373
Console.WriteLine("\t\t\t" + hostname);
374+
354375
Console.WriteLine("\t\tips:\n");
355-
foreach (string ip in ips)
376+
foreach (string ip in ips?.Items)
356377
Console.WriteLine("\t\t\t" + ip);
357378
}
358379
}
359380

381+
[Serializable()]
382+
public class WhoisHosts
383+
{
384+
[System.Xml.Serialization.XmlElement("Address")]
385+
public List<string> Items { get; set; }
386+
}
387+
360388
[Serializable()]
361389
public class WhoisRecordAudit
362390
{
@@ -426,25 +454,25 @@ public void PrintToConsole()
426454
Console.WriteLine("\t\tupdatedDate: " + updatedDate);
427455
Console.WriteLine("\t\texpiresDate: " + expiresDate);
428456
Console.WriteLine("\t\tregistrant:");
429-
registrant.PrintToConsole();
457+
registrant?.PrintToConsole();
430458
Console.WriteLine("\t\tadministrativeContact:");
431-
administrativeContact.PrintToConsole();
459+
administrativeContact?.PrintToConsole();
432460
Console.WriteLine("\t\tbillingContact:");
433-
billingContact.PrintToConsole();
461+
billingContact?.PrintToConsole();
434462
Console.WriteLine("\t\ttechnicalContact:");
435-
technicalContact.PrintToConsole();
463+
technicalContact?.PrintToConsole();
436464
Console.WriteLine("\t\tzoneContact:");
437-
zoneContact.PrintToConsole();
465+
zoneContact?.PrintToConsole();
438466
Console.WriteLine("\t\tdomainName: " + domainName);
439467
Console.WriteLine("\t\tnameServers:");
440-
nameServers.PrintToConsole();
468+
nameServers?.PrintToConsole();
441469
Console.WriteLine("\t\tstatus: " + status.Substring(0, (status.Length < 40 ? status.Length : 40)).Replace("\n", ""));
442470
Console.WriteLine("\t\trawText: " + rawText.Substring(0, (rawText.Length < 40 ? rawText.Length : 40)).Replace("\n", ""));
443471
Console.WriteLine("\t\theader: " + header.Substring(0, (header.Length < 40 ? header.Length : 40)).Replace("\n", ""));
444472
Console.WriteLine("\t\tstrippedText: " + strippedText.Substring(0, (strippedText.Length < 40 ? strippedText.Length : 40)).Replace("\n", ""));
445473
Console.WriteLine("\t\tfooter: " + footer.Substring(0, (footer.Length < 40 ? footer.Length : 40)).Replace("\n", ""));
446474
Console.WriteLine("\t\taudit:");
447-
audit.PrintToConsole();
475+
audit?.PrintToConsole();
448476
Console.WriteLine("\t\tregistrarName: " + registrarName);
449477
Console.WriteLine("\t\twhoisServer: " + whoisServer);
450478
Console.WriteLine("\t\treferralURL: " + referralURL);

0 commit comments

Comments
 (0)