php远程控制代码,Telnet与PHP。控制远程APC PDU

我试图通过执行一些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'作为用户名和密码。

所以也许你有一个想法的人,为什么成功重新加载我的代码不工作,因为它应该?为什么我不能回到主菜单并注销?

感谢您的时间。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值