473,569 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with stream (telnet to router)

Hallo to all,
I have write a little script for connecting to cisco router BUT I have a
problem: I have to send to router all the commands and then I have to read
the output.
If I send a command1 and read the output for command1 the script works
well,
If I sent command1 , I send command2 and then I read output for command1
and command2 it works well.
If i send command1 and then I read the output for command1 then send
command2 I can't read the output for the command 2.
Why?
How can I do?
Thank you in advance,
Mario.

P.S. following the script and the password

=============== =============== == SCRIPT =============== =============== ==
<?
include "router.php ";

$r=new Router();

$r->connect('route r_address', $errno, $errstr);

$r->login($myLogin ,$myPassword);
$o=$r->runCommand('sh o ver'); //<==== works
echo '<pre>';
var_dump($o);
echo '</pre>';

$o=$r->runCommand('sh o int descr'); //<==== don't works

$r->disconnect() ;

?>

=============== =============== ====== Class =============== =============== ============

<?

Class Router
{

function Router()
{
$this->connesso=0;
}

function connect($Server Address, $errno, $errstr, $cfgPort=23,$cf gTimeOut=10)
{
$this->stream= fsockopen($Serv erAddress, $cfgPort, $errno, $errstr, $cfgTimeOut);
if(!$this->stream)
{
$this->connesso=0;
}
else
{
$this->connesso=1;
}
}

function disconnect()
{
if($this->connesso==0){e xit();}
fwrite ($this->stream, "lo\r\n");
fclose($this->stream);
$this->connesso=0;
}

function login ($login,$passwo rd)
{
if($this->connesso==0){e xit();}

if(strlen($logi n)>0)
{
fputs ($this->stream, "$login\r\n ");
fputs ($this->stream, "$password\r\n" );
}
else
{
fputs ($this->stream, "$password\r\n" );
}

stream_set_time out($this->stream, 2);

fputs ($this->stream,"termin al length 0\r\n");
/*
if I send a list of commands here it get the command and i see the output
in next read of strream, for example:
fputs ($this->stream,"sho int desc\r\n"); fputs
($this->stream,"sho ver\r\n");
....
*/

}
function runCommand($com mand,$logoutput =0,$ntimeout=10 )
{

if(strlen($comm and)>0)
{
fputs ($this->stream, $command."\r\n" );
}
$output=array() ;
while(!feof($th is->stream))
{
$info = stream_get_meta _data($this->stream);
if ($info['timed_out'])
{
$ntimeout--;
usleep(100000);
}
else
{
$line=fread($th is->stream,1000) ;
$output[]=$line;
}
if ($ntimeout==0)
{
break;
}
}
return $output;
}

}//class Router
?>
May 16 '06 #1
0 3098

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2743
by: Jinming Xu | last post by:
Hello Everyone, I am trying to write a python script to telnet to a server and then do something there. As the first step, I practiced the python example in Lib Reference 11.13.2. But I am finding the script stops after I supplied the password. Does anyone know why? Thanks in advance!
6
6448
by: Richard Bird CCNP, CCDP, MCSE, etc. | last post by:
I need some help adding multithreading to an existing python script. The script was developed to telnet and make changes on a list of cisco routers. I figure that by adding multithreading, I'd be able to telnet to several routers concurrently and speed up the process of making changes. Is this feasible using python with its standard telnet...
2
3054
by: newsf | last post by:
Hi, I want to make a program what connect through telnet protocol to a router, and run commands for configure the router. I read over sockets and I made the program above, but it don´t work fine. After this, I read document in Internet about this, and I believe that I have to implement the protocol. But I don´t know. Someone can help me.
3
1452
by: Lidvar | last post by:
Hi. I wonder if anyone know a easy way to control a ISDN router in telnet, in visual basic..?
2
2949
by: _andrea.l | last post by:
I'm writing a little script for reading information from a router by telnet. I have a problem How give a comand and get the answer more times? I means: $usenet = fsockopen($cfgServer, $cfgPort, &$errno, &$errstr, $cfgTimeOut);
2
7692
by: vmalhotra | last post by:
Hi I am new in python scripting. I want to open a Multiple telnet session through once script. In other way i can tell i want to open two linux consoles through one script. I wrote one script, but the issue is I am not able to open multiple consoles. The Scripts which i wrote is as follows: import pexpect
3
4223
by: svjames | last post by:
Hey guys, im working on a project that requires a telnet connection to be made from a web page to a router, auto login then quit/drop whatever, its just gotta run one and in the background. my friend wrote me this code because i know nothing about java but i cant even begin to imagine how to make this thing run. Ive tried useing html tags like...
17
7329
by: ravimath | last post by:
Dear all, I have written following script to loin to router bu it is showing error. #!c:\Perl\bin; use strict; use warnings; my $hostname = 'REMOVED FOR YOUR PROTECTION'; my $password = 'REMOVED FOR YOUR PROTECTION';
2
4561
by: manuitpro | last post by:
Hi, I have implemented a php script by which i can login to a router using fsockopen(), and i can run any cisco commands. But i have requiremnt login to a remote from from a central router for the out of band management. How can make a script by whch i can login to another cisco router (telnet) from an already logged in router. my...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.