Hi there I know its my first post but I have been struggling with this for way too long.

I am trying to create a script that can pass data to telnet using curl or i should say libcurl I guess.

I can achieve what I am trying to do using sockets but unfortunately the host the script is to go on blocks these sorts of connections using sockets however as yet they haven't blocked curl.

I can get it to connect to the telnet but thats as far as i seem to get using the following

<?php

error_reporting(E_ALL);
ini_set('display_errors','On');

function curl_telnet($query,$server,$timeout=10) {
	if (!function_exists('curl_init')) {
		user_error('"curl_init()" function does not exist.', E_USER_WARNING);
		return false;
	}
    $ch = curl_init($server);

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

$result=curl_telnet("BLAAT",'telnet://*.*.*.*:6402')?'good':'fail';
echo "$result\n";

?>

Ok so basically this will connect to an eggdrop and pass some data to it the script on the eggdrop works fine as i say it works ok using sockets but I cant seem to figure out how to post to the data to the telnet connection using curl.

I have read the information on the curl website and i confess it confused me I'm no php guru and while I sort of understand what the stdin is I have no idea how I would go about writing the data to it so that it can be sent to the telnet server.

The libcurl TELNET support will read data on stdin and pass to the remote
peer, while it will pass incoming network data to the usual internal mumbo
jumbo.
So, to automate telnet with curl, you need:
- set telnet options (if you have any special ideas)
- make a connection to the remote host with 'telnet://hostname'
Then you'll get the data the host sends you the "normal" way, while you need
to somehow pass data to stdin to get them over to the other side.

Anyone that could at least point me in the right direction please ive looked at popen and process_open and again I feel I may be out of my depth with those.

    ShavedApe;10966798 wrote:

    php guru and while I sort of understand what the stdin is I have no idea how I would go about writing the data to it so that it can be sent to the telnet server.
    Anyone that could at least point me in the right direction please ive looked at popen

    IO Streams, stdin among others.

      Thanks for answering but I guess this is where Im lost I can find out what STDIN is but not how to directly edit it so that it can be sent to the telnet server.

      upon reading the link you supplied a link I have already viewed btw I find this

      php://stdin and php://input are read-only, whereas php://stdout, php://stderr and php://output are write-only.

      I dont really need an explanation as to what STDIN is that I can find more how to manipulate it so that I can add the data that needs to be written to the telnet server.

        I did want to just edit my post but i dont have the option.

        The link appears to tell me what input output streams are and that stdin is not writeable so I guess I need to somehow use php://input but im an very unclear on how to do so or if I am even in the right ball park

          If you run your script through CLI, keyboard input goes through php//stdin.

            forgive me but what is CLI ?
            I dont want the keyboard input I want to send already set variables as data.

              Command Line Interpreter

              In that case I suppose you could achieve your goal by sending your existing data to stdout and pipe it to your telnet script.

                Ok i guess this is beyond my capabilities then because even after I found this http://www.gorilla3d.com/v8/php-pipe-process.html I couldnt get it to work.
                I thought I understood it and i changed only the file that was called for to my telnet one. All it returned was this
                X-Powered-By: PHP/5.2.8
                Content-type: text/html

                Never realized it would be so difficult thanks for all your help.

                  Write a Reply...