Jump to content

PHP telnet connection


uwictech

Recommended Posts

Hi guy's,

 

I've found a way to connect to an appliance and change password information using PHP and TELNET.

 

I have a random password generator which puts the password into a variable, could I incorporate that into the telnet command?

 

J

 

 

<?php


function randomPass1 ($cut) {
global $string1;

    $string1 = md5(time());
    $string1 = substr($string1 , 0 , $cut);
    return $string1;

}

    echo randomPass1(;



?>
<?php


function randomPass2 ($cut) {
global $string2;

    $string2 = md5(time());
    $string2 = substr($string2 , 15 , $cut);
    return $string2;

}

    echo randomPass2(;



?>

<?php



require_once "php-telnet/PHPTelnet.php";

$telnet = new PHPTelnet();

// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1
$result = $telnet->Connect('192.168.##','admin','#');

if ($result == 0) {
$telnet->DoCommand('config wlan disable 1');
// NOTE: $result may contain newlines
$telnet->DoCommand('config wlan security wpa1 pre-shared-key enable 1 ascii $string1');

$telnet->DoCommand('config wlan enable 1');

// say Disconnect(0); to break the connection without explicitly logging out
$telnet->Disconnect();
}

Link to comment
https://forums.phpfreaks.com/topic/179201-php-telnet-connection/
Share on other sites

Thanks bricktop that looks better

 

I seem to be getting this error

Warning: Missing argument 2 for PHPTelnet::DoCommand(), called in C:\xampp\htdocs\telnet.php on line 45 and defined in C:\xampp\htdocs\php-telnet\PHPTelnet.php on line 95

 

This is that part of the code in the file it's pointing at

function DoCommand($c,&$r) {
	if ($this->fp) {
		fputs($this->fp,"$c\r");
		$this->Sleep();
		$this->GetResponse($r);
		$r=preg_replace("/^.*?\n(.*)\n[^\n]*$/","$1",$r);

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.