Jump to content

Telnet command through php


sama

Recommended Posts

Hello mate

I have this problem: I use a php script to pass commands to a router via telnet.. this code use another script ( which is attached here). I need to pass an enter, how could I do that?  :-\ what character should I put between the quotation? I tried to put 'e' but it doesn't work..please see the code..

 

<?php

session_start();

require_once "PHPTelnet.php";
require_once "password.php";

$telnet = new PHPTelnet(); // using a function from the included script

$result = $telnet->Connect('192.168.10.1','',''); //IP address of the router, username, password
	switch ($result)
	{
		case 0: 
		echo "Connected!!";

		    $telnet->DoCommand('engineer', $result);
			echo $result;	

			$telnet->DoCommand('sama', $result);
			echo $result;

			$telnet->DoCommand('who', $result); // to see the active telnet session
			echo $result;

			$telnet->DoCommand('clear line vty 0', $result); // disconnect the active once
			echo $result;

			[color=orange]$telnet->DoCommand(' ', $result); //to confirm the disconnect action, it need to press enter button. what should I put?
			echo $result;[/color]

			$telnet->DoCommand('exit', $result);
			echo $result;

		break; 
		case 1:
		echo '[php Telnet] Connect failed: Unable to open network connection';
		break; 
		case 2:
		echo '[php Telnet] Connect failed: Unknown host';
		break; 
		case 3:
		echo '[php Telnet] Connect failed: Login failed';
		break; 
		case 4:
		echo '[php Telnet] Connect failed: Your PHP version does not support PHP Telnet';
		break; 
	}
?>

 

[attachment deleted by admin]

Link to comment
Share on other sites

  • 2 years later...

Hello,

 

I sure am glad to see people using this PHP to preform this task. I am in need of doing so right now.

 

I have a website that I need to connect to a web server running nothing but telnet basically... I need to send a command and get the response.

 

Would you be willing to share the entire script your using?

 

My Best,

Jason

 

PS, Im so happ the /r would work, now SAMA, did the /r carriage return work?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.