> A really quick script to run a whois lookup, and format the response into JSON.
> Inspired by [whois-json](https://github.com/mikemaccana/whois-json) by @mikemaccana.
## Usage
**Prerequisites**
1. Paste the above code in a file, like `whois-lookup.js`
2. And then run `npm i html-entities change-case whois`
---
  Usage Example 1: In your code
  
```javascript
import { getWhoisData } from './whois-lookup.js';
    
getWhoisData('google.com').then(data => {
  console.log(data); // Outputs a JSON WHOIS response
}).catch(error => {
  console.error(error);
});
```
  
 
---
  Usage Example 2: As an API
  
  
1. Create a file named `server.js`, and paste the code below into it
2. Run `node server`
3. Open `localhost:3000/duck.com` to return the WHOIS JSON
```javascript
import { getWhoisData } from './whois-lookup.js';
import http from 'http';
const server = http.createServer((req, res) => {
  const urlParts = req.url.split('/');
  const domain = urlParts[1];
  
  if (domain) {
    getWhoisData(domain).then(data => {
      res.writeHead(200, { 'Content-Type': 'application/json' });
      res.end(JSON.stringify(data, null, 2));
    }).catch(error => {
      res.writeHead(500, { 'Content-Type': 'text/plain' });
      res.end(`Error: ${error.message}`);
    });
  } else {
    res.writeHead(400, { 'Content-Type': 'text/plain' });
    res.end('Please specify a domain in the URL. For example: /example.com');
  }
});
server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});
```
  
 
---
  Usage Example 3: As a CLI
  
  
1. Create a file named `whois-cli.js`, and paste the code below into it
2. In your terminal, run `node ./whois-cli.js --url='google.com'` to get WHOIS JSON
```javascript
import { getWhoisData } from './whois-lookup.js';
const args = process.argv.slice(2);
const domainArg = args.find(arg => arg.startsWith('--url='));
if (domainArg) {
  const domain = domainArg.split('=')[1];
  getWhoisData(domain).then(data => {
    console.log(data);
  }).catch(error => {
    console.error('Error:', error);
  });
} else {
  console.log('Usage: node ./example.js --url="example.com"');
}
```
  
 
---
  Example Output (JSON)
  
```json
{
  "domainName": "google.com",
  "registryDomainId": "2138514_DOMAIN_COM-VRSN",
  "registrarWhoisServer": "whois.markmonitor.com",
  "registrarUrl": "http://www.markmonitor.com",
  "updatedDate": "2024-08-02T02:17:33+0000",
  "creationDate": "1997-09-15T07:00:00+0000",
  "registrarRegistrationExpirationDate": "2028-09-13T07:00:00+0000",
  "registrar": "MarkMonitor, Inc.",
  "registrarIanaId": "292",
  "registrarAbuseContactEmail": "abusecomplaints@markmonitor.com",
  "registrarAbuseContactPhone": "+1.2086851750",
  "domainStatus": "clientUpdateProhibited (https://www.icann.org/epp#clientUpdateProhibited) clientTransferProhibited (https://www.icann.org/epp#clientTransferProhibited) clientDeleteProhibited (https://www.icann.org/epp#clientDeleteProhibited) serverUpdateProhibited (https://www.icann.org/epp#serverUpdateProhibited) serverTransferProhibited (https://www.icann.org/epp#serverTransferProhibited) serverDeleteProhibited (https://www.icann.org/epp#serverDeleteProhibited)",
  "registrantOrganization": "Google LLC",
  "registrantStateProvince": "CA",
  "registrantCountry": "US",
  "registrantEmail": "Select Request Email Form at https://domains.markmonitor.com/whois/google.com",
  "adminOrganization": "Google LLC",
  "adminStateProvince": "CA",
  "adminCountry": "US",
  "adminEmail": "Select Request Email Form at https://domains.markmonitor.com/whois/google.com",
  "techOrganization": "Google LLC",
  "techStateProvince": "CA",
  "techCountry": "US",
  "techEmail": "Select Request Email Form at https://domains.markmonitor.com/whois/google.com",
  "nameServer": "ns4.google.com ns3.google.com ns2.google.com ns1.google.com",
  "dnssec": "unsigned",
  "urlOfTheIcannWhoisDataProblemReportingSystem": "http://wdprs.internic.net/",
  "lastUpdateOfWhoisDatabase": "2024-10-19T14:27:44+0000 <<<",
  "forMoreInformationOnWhoisStatusCodesPleaseVisit": "https://www.icann.org/resources/pages/epp-status-codes",
  "webBasedWhois": "https://domains.markmonitor.com/whois",
  "lawfulPurposesAndThatUnderNoCircumstancesWillYouUseThisDataTo": "(1) allow, enable, or otherwise support the transmission by email, telephone,"
}
```
  
 
---
    
> [!NOTE]
> Hate JavaScript? Me too. I've written a Go Lang version, here: [github.com/Lissy93/who-dat](https://github.com/Lissy93/who-dat). Much better 😎