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
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);

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.