How do I run a WHOIS lookup with PHP or Python?

前端 未结 5 1860
鱼传尺愫
鱼传尺愫 2020-12-05 21:30

So anyways, I\'m working on a small PHP website/script, and as one of the features I\'d like to be able to run a WHOIS lookup on the current domain the PHP script is running

相关标签:
5条回答
  • 2020-12-05 21:50

    With php you can use shell_exec to execute the whois command.

        <?php
        $whois = shell_exec("whois domain.net");
        echo '<pre>';
        print_r($whois);
        ?>
    
    0 讨论(0)
  • 2020-12-05 21:55

    This should do exactly what you want... http://www.phpwhois.org/

    I've used this class before, doing exactly what you want!

    0 讨论(0)
  • 2020-12-05 22:01

    To take Pavels answer one step further - this will break it down in to an array:

    $whois = shell_exec("whois 45.118.135.255");
    
    $result = explode("\n",$whois);
    
    $out = array();
    foreach ($result as $line){
        if (substr($line,0,1) == '%' || substr($line,0,1) == '#'){ continue; }
    
        $ps = explode(':',$line);
        $out[trim($ps[0])] = trim($ps[1]);
    }
    
    print '<pre>'; print_r($out); print '</pre>';
    
    0 讨论(0)
  • 2020-12-05 22:06

    Try the Function Which is available in github gist

    https://gist.github.com/AManojKiran/4b034659e85fa02308ad9bdcdd05629c

    For the full list of TLDs/Whois servers see http://www.iana.org/domains/root/db/ and http://www.whois365.com/en/listtld/

    0 讨论(0)
  • 2020-12-05 22:10

    Best thing to do would be to use pywhois. Though you say Python in the question title but don't mention it in the post. If you actually need PHP, I'm sure there's something equivalent for that.

    0 讨论(0)
提交回复
热议问题