Before I report this as a bug, can anyone provide an example of how to
interface with a telnet server using curl?
Here's what I've tried, with various results:
<pre>
<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
function curl_telnet($query,$server,$proxy=false,$timeout=10) {
if (!function_exists('curl_init')) {
user_error('"curl_init()" function does not exist.', E_USER_WARNING);
return false;
}
$ch = curl_init($server);
if ($proxy) {
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $query);
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
$tests=array();
$tests['rainmaker.wunderground.com:23']="\r\n\r\nx\r\n";
$tests['telnet://rainmaker.wunderground.com:23']="\r\n\r\nx\r\n";
$tests['towel.blinkenlights.nl:666']='';
$tests['telnet://towel.blinkenlights.nl:666']='';
$tests['whois.iana.org:43']="com\r\n";
$tests['telnet://whois.iana.org:43']="com\r\n";
foreach ($tests as $server => $query) {
$result=curl_telnet($query,$server)?'good':'fail';
echo "$server=$result\n";
}
?>
This results as following:
rainmaker.wunderground.com:23=good
telnet://rainmaker.wunderground.com:23=fail
towel.blinkenlights.nl:666=good
telnet://towel.blinkenlights.nl:666=good
whois.iana.org:43=good
telnet://whois.iana.org:43=fail
The obvious issue is that when you're not using the telnet:// protocol the
HTTP request is always sent. However, in some cases, when a query is sent,
using telnet:// will fail.
Is this a bug or is anyone else able to get telnet with curl to work as
expected?
Thanks.