Skip to content

Commit c2161d8

Browse files
committed
Add code sample on PowerShell
- Add whois api code smaple on PowerShell. - Add example of using response data in NodeJS sample.
1 parent 76affbc commit c2161d8

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

nodejs/sample.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,19 @@ https.get(url, function (res) {
2929
});
3030
res.on('end', function () {
3131
try {
32-
var parsedData = JSON.stringify(rawData);
33-
console.log(parsedData);
32+
var parsedData = JSON.parse(rawData);
33+
if (parsedData.WhoisRecord) {
34+
console.log(
35+
'Domain name: '
36+
+ parsedData.WhoisRecord.domainName
37+
);
38+
console.log(
39+
'Contact email: '
40+
+ parsedData.WhoisRecord.contactEmail
41+
);
42+
} else {
43+
console.log(parsedData);
44+
}
3445
} catch (e) {
3546
console.log(e.message);
3647
}

powershell/sample.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
$uri = "https://www.whoisxmlapi.com/whoisserver/"`
2+
+"WhoisService?domainName=google.com"`
3+
+"&username=xxxx&password=xxxxxxx"`
4+
+"&outputFormat=json"
5+
6+
$j = Invoke-WebRequest -Uri $uri -UseBasicParsing | `
7+
ConvertFrom-Json
8+
9+
if ([bool]($j.PSObject.Properties.name -match "WhoisRecord")) {
10+
echo "Domain Name: $($j.WhoisRecord.domainName)"
11+
echo "Contact Email: $($j.WhoisRecord.contactEmail)"
12+
} else {
13+
echo $j
14+
}

0 commit comments

Comments
 (0)