Quick and Easy PHP WHOIS Script

I like to be able to type “whois somedomain.com” in my browser and have it bring up the WHOIS infor­ma­tion. The site I’ve been using has a captcha (annoy­ing) and has got­ten unre­li­able, so I wrote this quick and easy script to pull the full unfor­mat­ted WHOIS data for me:

<?php $d =  isset($_GET['d']) ? $_GET['d'] : ''; ?>
<html>
<head>
<title>WHOIS <?php echo $d; ?></title>
</head>
<body>
<pre>
<?php
if(!empty($d)){
    exec("whois ".escapeshellarg($d), $results);

    if(isset($_GET['debug'])){
        print_r($results);
    }

    $server = '';

    foreach($results as $result){
        if(stripos($result, 'whois server:')){
            $server = trim(str_replace('whois server:','',strtolower($result)));
        }
    }

    if(!empty($server)){
        passthru("whois -h ".escapeshellarg($server)." ".escapeshellarg($d));
    }else{
        foreach($results as $result){
            echo $result.PHP_EOL;
        }
    }

}
?>
</pre>
</body>
</html>

This script should work out-of-the-box for most Linux installations.

You can make the “whois somedomain.com” func­tion­al­ity work in Fire­fox by cre­at­ing a book­mark with a loca­tion of: http://www.yourdomain.com/whois.php?d=%s

I’d highly rec­om­mend you put this script in a pass­word pro­tected direc­tory to pre­vent abuse!

This entry was posted in Web Dev. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>