Skip to content

Instantly share code, notes, and snippets.

@dale-c-anderson
Last active February 11, 2024 08:49
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dale-c-anderson/eda188efbfc18a89ba7bfd1c52cc2dad to your computer and use it in GitHub Desktop.
Save dale-c-anderson/eda188efbfc18a89ba7bfd1c52cc2dad to your computer and use it in GitHub Desktop.
Simple PHP whois lookup script
<form method=GET action="<?php htmlentities(basename(_FILE_)); ?>">
<input type=text name="q" value="<?php echo htmlentities($_REQUEST["q"]); ?>">
<input type=submit value="WHOIS">
</form>
<pre><?php
/*
* whois.php
*/
main();
function main(){
$domain = $_REQUEST['q'];
if (!$domain) {
return FALSE;
}
if (!is_valid_domain_name($domain)) {
echo "Invalid query";
return FALSE;
}
if (strlen($domain) < 4) {
echo "No domain name is that short.";
return FALSE;
}
if (strlen($domain) > 80) {
echo "Too long.";
return FALSE;
}
//echo '$ whois ' . htmlentities($domain) . "\r\n";
$whois = shell_exec("whois '" . addslashes($domain) . "'");
print_r($whois);
}
function is_valid_domain_name($domain_name) {
// Thanks to http://stackoverflow.com/a/4694816
return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check
&& preg_match("/^.{1,253}$/", $domain_name) //overall length check
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name) ); //length of each label
}
@justanthonylee
Copy link

Oh wow this is awesome, today I had the need to Google "Whois PHP script" and this was the first result and made me remember you can just get the info via shell or terminal.

THEN I saw who posted it.

👋

@dale-c-anderson
Copy link
Author

What a small world! 👍

@kamel3d
Copy link

kamel3d commented Apr 22, 2021

Oh wow this is awesome, today I had the need to Google "Whois PHP script" and this was the first result and made me remember you can just get the info via shell or terminal.

THEN I saw who posted it.

👋

Do you know where can I find the terminal version? thanks

@dale-c-anderson
Copy link
Author

@kamel3d , whois is a standalone package in most major distros.

@alsyundawy
Copy link

hallo can you update Root Zone Database TLD from IANA db https://www.iana.org/domains/root/db & public suffix https://publicsuffix.org/list/

@dale-c-anderson
Copy link
Author

@alsyundawy That's beyond what this script can control. Try updating your OS's whois package to a newer version instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment