Use fsockopen with a proxy server

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 information domains

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

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

But this will not work, I do not know if I will make the second connection correctly.

+4
source share
1 answer

Sending your request to the proxy server 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); ?> 

Instead, I would recommend that you use CURL in combination with:

 curl_setopt($ch, CURLOPT_PROXY, 1.2.3.4); 
+5
source

Source: https://habr.com/ru/post/1416026/


All Articles