uwictech Posted October 27, 2009 Share Posted October 27, 2009 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(); } Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 27, 2009 Share Posted October 27, 2009 Hi uwictech, You should be able to do: $result = $telnet->Connect('192.168.##','admin',$string1); Change $string1 to $string2 if that's the password you want to use. Hope this helps. Quote Link to comment Share on other sites More sharing options...
uwictech Posted October 27, 2009 Author Share Posted October 27, 2009 Hi Bricktop I need variable in the $telnet->DoCommand('config wlan security wpa1 pre-shared-key enable 1 ascii $string1'); I think I've solved it. I just used " " in stead of ' ' J Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 27, 2009 Share Posted October 27, 2009 Hi Jamie, If you would like it in that line you just need to concatenate the variable. For example: $telnet->DoCommand('config wlan security wpa1 pre-shared-key enable 1 ascii '.$string1.''); Quote Link to comment Share on other sites More sharing options...
uwictech Posted October 27, 2009 Author Share Posted October 27, 2009 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.