dongxiaoxiao1983 2012-09-13 22:12
浏览 299
已采纳

PHP fsockopen通过代理

I am currently using PHP to open up a port 43 connection to get whois information directly from a registry using this code.

// connecting to the whois server.  
$handle = fsockopen($server, 43);  
        if (!$handle)  
            return false; // connection failure   


        //asking the server  
        fwrite($handle, $domain_name."
");  


        // getting response  
        $response = '';  
        while (!feof($handle))  
            $response .= fgets($handle, 1024);  

        fclose($handle);

It works great however I want to connect though a proxy server so I route my intertent connection through it. If this were able to use cURL I would use curl_setopt($curl_handle, CURLOPT_PROXY, $ip_address . ':4040'); but i can not find a way to do this using fsocketopen. How can I accomplish this either with cURL or fsocketopen()?

  • 写回答

2条回答 默认 最新

  • duanpo7354 2012-09-13 23:37
    关注

    Sockets dont have proxy. Just gateways and routers are in-the-middle (if any). You were talking about cURL, that it has proxy - it only uses http/s proxy service. For example, if you have http proxy service on server example.com:8080 you first need to open connection to server example.com (socket) on port 8080 and then send your request, proxy will forward your request and return response. In your case, you just open tcp connection on port 43 on specific host and exchange data directly with target server. If you dont want to do this directly and reveal your ip (or something) you'll need some service too. If you have access to other machine you could use it to do the job. If you want to do it manually you could use ssh or something like that, if you want to make it automatized, you'll probably need to write service on your middle server because you probably wont find any public proxy servers with other protocols than popular http, ftp, ...

    Hope this helps.

    By the way I see no reason why you should use proxy on whois service.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?