Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8292251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:24:45+00:00 2026-06-08T13:24:45+00:00

I am executing commands( fputs ) on socket/telnet console and getting output/result( fread )

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:24:47+00:00Added an answer on June 8, 2026 at 1:24 pm

    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.

    $stream = stream_socket_client("tcp://10.1.1.1:23", $errno, $errstr, 30);
    if (!$stream ) {
        echo "$errstr ($errno)<br />\n";
    } else {
        fwrite($stream , "sh run" . PHP_EOL);
    
        // Set Blocking Mode - Wait For A Response On The Stream
        stream_set_blocking( $stream , true );
        while( true ){
    
            // This is your response
            echo stream_get_contents( $stream );
        }
    
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this code on python, that retrieves output from console when executing
Possible Duplicate: Get output from a process Executing DOS commands from Java I am
I'm executing these commands from a Console Application DBCC SHRINKFILE (@FILE_NAME_MDF, 0) WITH NO_INFOMSGS
I'm executing commands remotely through ssh. Is it possible to send output or commands
I learned that when executing commands in Python, I should use subprocess. What I'm
I often find myself executing commands like this at bash : history | grep
I need something like make i.e. dependencies + executing shell commands where failing command
I'm trying to start unicorn_rails in a ruby script, and after executing many commands
I am creating a Python script within which I am executing UNIX system commands.
I have read the other posts, e.g., vim: Executing a list of editor commands

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.