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
https://forums.phpfreaks.com/topic/198080-telnet-command-through-php/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.