Last active
September 22, 2023 06:24
-
-
Save johnroyer/8d27be240f972a505cd53a27a461588f to your computer and use it in GitHub Desktop.
whois query using TCP socket in PHP
This file contains 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
<?php | |
error_reporting(E_ALL); | |
echo "connection to whois.twnic.net.tw\n"; | |
$address = gethostbyname('whois.iana.org.'); | |
$fp = @fsockopen($address, 43, $errno, $errstr, 5) or die("Socket Error " . $errno . " - " . $errstr); | |
stream_set_blocking($fp, true); | |
echo "socket openned\n"; | |
// whois protocol RFC | |
// https://www.rfc-editor.org/rfc/rfc3912.txt | |
echo "sending request ... "; | |
$query = 'zeroplex.tw' . "\r\n"; | |
fputs($fp, $query); | |
echo "ok \n"; | |
echo "closing socket ... "; | |
fclose($fp); | |
echo "ok\n"; | |
$refer = preg_match('/refer: +([^ ]+)/', $result, $matches); | |
if (1 === $refer) { | |
echo "refer found: "; | |
var_dump($matches); | |
} else { | |
echo "--------------- \n"; | |
echo $result . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment