Jump to content

WHOIS & DNS check


Steve75

Recommended Posts

Hey Steve,

I just built this on my own WHMCS and it works well. It's a custom client area page that shows the domain status, DNS records and full WHOIS, all inside your theme's header, footer and menu. WHOIS goes through WHMCS's own DomainWhois API, so it uses the same lookup servers your domain checker already uses. DNS uses PHP's dns_get_record().

You need two files.

1. dnscheck.php in your WHMCS root folder:

<?php
use WHMCS\ClientArea;

define('CLIENTAREA', true);
require __DIR__ . '/init.php';

$ca = new ClientArea();
$ca->setPageTitle('WHOIS & DNS Lookup');
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('dnscheck.php', 'WHOIS & DNS Lookup');
$ca->initPage();

$domain = strtolower(trim($_POST['domain'] ?? ''));
$records = [];
$whois = '';
$status = '';
$error = '';

if ($domain !== '') {
    if (!filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) || strpos($domain, '.') === false) {
        $error = 'Please enter a valid domain name.';
    } else {
        $result = localAPI('DomainWhois', ['domain' => $domain]);
        if (($result['result'] ?? '') === 'success') {
            $status = $result['status'];
            $whois = html_entity_decode(strip_tags(urldecode($result['whois'] ?? '')), ENT_QUOTES);
        }
        $records = @dns_get_record($domain, DNS_A | DNS_AAAA | DNS_CNAME | DNS_MX | DNS_NS | DNS_TXT) ?: [];
    }
}

$ca->assign('domain', $domain);
$ca->assign('records', $records);
$ca->assign('whois', $whois);
$ca->assign('status', $status);
$ca->assign('error', $error);
$ca->setTemplate('dnscheck');
$ca->output();

 

2. dnscheck.tpl in your active theme folder (templates/yourtheme/):

<form method="post" action="dnscheck.php">
  <div class="input-group mb-3">
    <input type="text" name="domain" class="form-control" value="{$domain|escape}" placeholder="example.com">
    <button class="btn btn-primary" type="submit">Look Up</button>
  </div>
</form>

{if $error}<div class="alert alert-warning">{$error}</div>{/if}

{if $status}
<p><strong>Status:</strong> {if $status == 'available'}Available to register{else}Registered{/if}</p>
{/if}

{if $records}
<h4>DNS Records</h4>
<table class="table table-striped">
  <tr><th>Type</th><th>Host</th><th>Value</th><th>TTL</th></tr>
  {foreach $records as $r}
  <tr>
    <td>{$r.type}</td>
    <td>{$r.host|escape}</td>
    <td>{if $r.ip}{$r.ip}{elseif $r.ipv6}{$r.ipv6}{elseif $r.target}{if $r.pri}{$r.pri} {/if}{$r.target|escape}{elseif $r.txt}{$r.txt|escape}{/if}</td>
    <td>{$r.ttl}</td>
  </tr>
  {/foreach}
</table>
{/if}

{if $whois}
<h4>WHOIS</h4>
<pre style="white-space:pre-wrap;color:inherit;background:rgba(255,255,255,.05);padding:15px;border-radius:4px;">{$whois|escape}</pre>
{/if}

 

Then go to yourwhmcs.com/dnscheck.php and you're set. You can add it to your menu with a navbar hook, or just link to it from your site.

A couple of notes:
- The color:inherit on the WHOIS box makes it readable on both dark and light themes.
- Since it's a public page, I'd add a captcha or rate limit so bots don't hammer it.
- A lot of WHOIS records hide owner details now because of privacy rules, so you'll mostly see the registrar, dates and nameservers.

Hope that helps!

Rob
K & K Web Services

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated