I am executing commands(fputs) on socket/telnet console and getting output/result(fread) by below code and it’s working perfectly fine.
//open socket let's say ip = 192.168.10.5 and port = 21
$this->socketResource = fsockopen($this->nodeIp,$this->portNumber);
//execute some commands, for example "ipconfig"
fputs($this->socketResource,$command);
//get output string
$output = fread($this->socketResource,30000);
Now my requirement is to get all console/socket output without executing any command by fputs. For example, Cisco routers give continuous debug messages/prints on the telnet console/socket without executing any command by fputs.
How can i capture(fread) any telnet session output continuously for some duration without executing any command(fputs)?
If i capture in discrete fashion like every x seconds, i will definitely miss some console output.
For this, I would would switch over to the
stream_*family. There is a huge improvement when trying to accomplish the above with performance and extending.You will need to add something above to break the
while(true)loop, or the script will run forever, but this is an approach I use to do something similar.