4

I have a simple whois script

    if($conn = fsockopen ($whois_server, 43)) {
        fputs($conn, $domain."\r\n");
        while(!feof($conn)) {
            $output .= fgets($conn, 128);
        }
        fclose($conn);
        return $output;
    }

$whois_server = whois.afilias.info; //whois server for info domains

but I want to run in through proxy. So I need to connect to proxy -> then connect to whois server -> and then make the request. Something like this?

$fp = fsockopen($ip,$port);

fputs($fp, "CONNECT $whois_server:43\r\n $domain\r\n");

But it doesn't work, I don't know if i'm making the second connection right.

j0k
  • 22,600
  • 28
  • 79
  • 90
nacholibre
  • 3,874
  • 3
  • 32
  • 35
  • 1
    Why are you using a proxy? If it's because you've hit the rate limit on the Afilias WHOIS server, you need to contact Afilias about bulk WHOIS access -- using proxies will just get the proxies blocked too. –  Jun 04 '12 at 19:30

1 Answers1

5

Sending your request to the proxy should do what you like:

<?php
    $proxy = "1.2.3.4"; // proxy 
    $port = 8080; // proxy port

    $fp = fsockopen($proxy,$port); // connect to proxy
    fputs($fp, "CONNECT $whois_server:43\r\n $domain\r\n");

    $data="";
    while (!feof($fp)) $data.=fgets($fp,1024);
    fclose($fp);
    var_dump($data);
?>

Rather than doing that I would recommend you using CURL in combination with:

curl_setopt($ch, CURLOPT_PROXY, 1.2.3.4);