Last active
February 11, 2024 08:49
-
-
Save dale-c-anderson/eda188efbfc18a89ba7bfd1c52cc2dad to your computer and use it in GitHub Desktop.
Simple PHP whois lookup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 | |
} |
What a small world! π
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
@kamel3d , whois
is a standalone package in most major distros.
hallo can you update Root Zone Database TLD from IANA db https://www.iana.org/domains/root/db & public suffix https://publicsuffix.org/list/
@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
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.
π