Which command for "whois.pir.org" in PHP with Curl? - php

I need to test a whois service to test domain names with PHP and a proxy connection with authentification. It works very well for whois.verisign-grs.com for the .com or whois.nic.fr for the .fr, but for the .org, I have the following result, and I don't understand what command it is waiting for?
I couldn't find a doc to refer me.
Thanks !
result : string(57) "Neither object nor interpretation control keyword found
"
$server='whois.pir.org';
$domain='archive.org';
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$server);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_PROXYPORT, $port);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'CURLPROXY_SOCKS5');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $userpass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "$domain \r\n");
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "-T dn $domain\r\n");
$result = curl_exec($ch);
var_dump($result);
curl_close($ch);

WHOIS is NOT a HTTP protocol.
If you need to access the WHOIS information via cURL, I suggest you to look into the existing API providers such as JSONWHOIS, IP2WHOIS or WHOXY.

Related

Aliexpress blocks any request with proxy

Recently Aliexpress started to block all requests sent through a proxy.
I tried many ways like:
CURL
file_get_contents
tream_get_contents
But all of them got blocked whenever I add proxy and it works normally when I remove it.
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1");
curl_setopt($ch, CURLOPT_URL, $main_url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE , 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_PROXY, "proxy");
I also tried to add all kinds of headers.
How can I prevent Aliexpress from known that this is a proxy curl request?

PHP cURL GET Request Through SOCKS5 with Authentication

I'm trying to perform a web request through a SOCKS5 proxy with authentication, but it's not working and I can't work out why. Here's my code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
curl_setopt($ch, CURLOPT_PROXY, 'host:port');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:pass');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
return curl_exec($ch);
When I use curl_getinfo($ch, CURLINFO_HTTP_CODE), it says the response code is 0. Am I missing something obvious here? The proxy works fine with other programs I use, so I know it isn't an issue with the proxy.

Site not loading using curl

<?php
$url='https://source.amazon.com/forcelogin?returnToURL=https://www.amazon.com/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
curl_setopt($ch, CURLOPT_COOKIEFILE,'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
$data = curl_exec($ch);
curl_close($ch);
?>
I don't know why it doesn't load the website.
If I put regular sites like google.com, amazon.com or anything else is working.Anyone can help me out?
You need to add CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options to access HTTPS URL.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

using curl through a proxy with php

Any idea where my code is going wrong...I am trying to connect through a proxy with the curl function in php...I assuming the proxy worked bc I tried a few from this list http://hidemyass.com/proxy-list/search-234921 but cant seem to get any to function correctly...
Thoughts?
function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)')
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, '75.74.244.122:1523');
$data = curl_exec();
curl_close($ch);
return $result;
}
It doesn't look like the proxy you are using is working:
jasonfunk#jasonfunk-laptop:$ telnet 75.74.244.122 1523
Trying 75.74.244.122...
telnet: Unable to connect to remote host: Connection refused
You can try multiple proxy by using random one by one using this script
Get random proxy
function get_random_proxy(){
srand ((double)microtime()*1000000);
$f_contents = file ("proxy.txt");
$line = $f_contents[array_rand ($f_contents)];
return $line;
}
call curl function using one proxy randomly
function get_curl_proxy($url){
$proxy_ip = get_random_proxy();
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/532.4 (KHTML, like Gecko) Chrome/4.0.233.0 Safari/532.4";
$referer = "http://www.google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
For further reference see this
http://altafphp.blogspot.in/2012/06/using-proxies-with-curl-in-php.html

cURL Proxy issues 407

The Following gives me a 407 error, Can anyone see why or where I'm going wrong?
I am behind a proxy.
I have spent a while on this.
I'm using the correct credentials.
Thanks
function pushMeTo($widgeturl,$text,$signature) {
$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12";
if (!function_exists("curl_init")) die("pushMeTo needs CURL module, please install CURL on your php.");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $widgeturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:pass');
curl_setopt($ch, CURLOPT_PROXY, "IP");
curl_setopt($ch, CURLOPT_PROXYPORT, 8080);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$page = curl_exec($ch); //or die("Curl exe failed");
print_r(curl_error($ch));
print_r($page);
preg_match("/form action=\"(.*?)\"/", $page, $form_action);
preg_match("/textarea name=\"(.*?)\"/", $page, $message_field);
preg_match("/input type=\"text\" name=\"(.*?)\"/", $page, $signature_field);
//print_r($message_field);
$ch = curl_init();
$strpost = $message_field[1].'=' . urlencode($text) . '&'.$signature_field[1].'=' . urlencode($signature);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strpost );
curl_setopt($ch, CURLOPT_URL, $form_action[1]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$page = curl_exec($ch);
}
?>
<?
$url = "MY URL";
pushmeTo ($url,"This Is A Test","ServiceDesk");
?>
The answer was to add:
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
After that everything worked!
Try adding:
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP'); // just a guess
If this does not work for you then check if mod_proxy apache module is loaded or not.
If thats also loaded , then try recompiling curl module using latest version
Hope it helps you in debugging.
Check the bottom, where you use the function. Should have a capitol M.

Categories