我试图通过执行一些PHP命令来控制远程电源开关。
有一个telnet库用于建立telnet连接:http://www.soucy.org/project/cisco/source.php
我的连接功能如下所示:
public function connect()
{
$this->_connection = fsockopen($this->_hostname, $this->_port, $errno, $errstr, $this->_timeout);
if ($this->_connection === false) {
die("Error: Connection Failed for $this->_hostname\n");
} // if
stream_set_timeout($this->_connection, $this->_timeout);
$this->_readTo(':');
if (substr($this->_data, -9) == 'Username:') {
$this->_send($this->_username);
$this->_readTo(':');
} // if
$this->_send($this->_password);
$this->_send(''); //blank space, because we need to press for the second login prompt
//Login Second time
$this->_send($this->_username2);
$this->_send($this->_password2);
}发送函数如下所示:
private function _send($command)
{
fputs($this->_connection, $command . "\r\n");
}所以如果我们想要控制远程电源开关,有一个菜单。在这个菜单中,用户可以像这样导航:
-------控制台----------------------------------------- --------------
1- Device Manager
2- Network
3- System
4- Logout
- Main Menu, - Refresh
当我们按1时,我们会去另一个meniu:
- - - - 装置经理 - - - - - - - - - - - - - - - - - - - - - ---------------
1- Bank Monitor
2- Outlet Management
3- Power Supply Status
- Back, - Refresh
等等......所以我们可以通过输入这些数字来访问我们想要的插座。
重新装入插座的功能(插座号码22):
public function ReloadOutlet22()
{
$this->_send('1'); // Access Device Manager
$this->_send('2'); // Access Outlet Management
$this->_send('1'); // Outlet Control/Configuration
$this->_send(); // ' to continue'
$this->_send('22'); // Access Outlet number 22
$this->_send('6'); // Delayed Reboot (reboot with 5 sec delay)
$this->_send('YES'); // 'Yes' to continue
$this->_send(); // to continue'
//Everything is working till there. I can successfully reload the outlet which I want. After the reload I want to go to the main menu and logout from this console.
$this->_send('\e'); // - back
$this->_send('\e'); // - back
$this->_send('\e'); // - back
$this->_send('\e'); // - back
$this->_send('\e'); // - back
$this->_send('4'); // Logout
}所以有一个问题。下一次,当我想重新加载另一个插座时,例如23号插座,我无法成功登录到APC PDU。我可以在登录提示中看到有人尝试使用'\ e'作为用户名和密码。
所以也许你有一个想法的人,为什么成功重新加载我的代码不工作,因为它应该?为什么我不能回到主菜单并注销?
感谢您的时间。