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

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

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

我目前正在使用PHP打开端口43连接,使用此代码直接从注册表获取whois信息。

  //连接到whois服务器。  
 $ 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 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条)

相关推荐 更多相似问题