How to run a WHOIS search using PHP or Python?

Somehow, I work on a small PHP / script website, and as one of the functions that I would like to use to search for WHOIS in the current domain that the PHP script is running on.

Ideally, this would be one function that I could name, and in the function, it launched WHOIS, and then echoed the results on the screen. The WHOIS URL will require the website URL, or it will just run it in the current URL / domain (this is what I want), although I can supply it as a variable for the website domain if necessary.

I know little about WHOIS searches (well, I know what they do, I just don’t know how to run them in PHP), but I will also be fine with a request to another site (even one of my own, if you can give me code for it).

Whatever works, just let me know! The main thing is that I would prefer it to correspond to all in one function, and it should definitely fit into one PHP file / document.

+5
php whois
source share
4 answers

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

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

+5
source share

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

<?php $whois = shell_exec("whois domain.net"); echo '<pre>'; print_r($whois); ?> 
+6
source share

To take Paul one step further - this will break it into 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>'; 
+2
source share

It would be best to use pywhois . Although you say Python in the title of the question, but don't mention it in the post. If you really need PHP, I'm sure there is something equivalent for this.

0
source share

All Articles