How can fsockopen be utilized to perform a Whois query in PHP for IP address information?
To perform a Whois query in PHP for IP address information, you can use the fsockopen function to connect to the Whois server and send a query. You will need to specify the Whois server for the IP address you want to query. Once connected, you can send the query and read the response to retrieve the information.
$ip = '192.168.1.1';
$whois_server = 'whois.arin.net';
$port = 43;
$socket = fsockopen($whois_server, $port, $errno, $errstr, 30);
if (!$socket) {
echo "$errstr ($errno)<br>";
} else {
fwrite($socket, $ip . "\r\n");
while (!feof($socket)) {
echo fgets($socket, 128);
}
fclose($socket);
}