2012-09-13 22:12
浏览 283

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);  


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()?

图片转代码服务由CSDN问答提供 功能建议


 $ handle = fsockopen($ server,43);  
 if(!$ handle)
返回false;  //连接失败
 fwrite($ handle,$ domain_name。“
 $ response ='';  
 while(!feof($ handle))
 $ response。= fgets($ handle,1024);  
 fclose($ handle); 

它工作得很好但是我想通过代理服务器连接,所以我通过它来路由我的intertent连接。 如果能够使用cURL,我会使用curl_setopt($ curl_handle,CURLOPT_PROXY,$ ip_address。':4040'); 但我找不到使用fsocketopen做到这一点的方法。 如何使用cURL或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 you first need to open connection to server (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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题