dongzituo5530 2013-05-12 05:07
浏览 26
已采纳

用于修改cico dhcp池的php脚本

I'm trying to automate a process of a modem provisioning system. the code below is my attempt with the exception of a form that i did not list that is passing the variables.

the DB portion of the script is working well. however the telnet portion is not making it into the router as I had hoped can anyone shed some light on this. if I break the telnet portion out and run it via cli it works.

<?

include("config.php");
//setting up db connection
try{
$dbh = new PDO("mysql:host=$host;dbname=$db", $mun, $mpass);
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );


 $stmt = $dbh->prepare("INSERT INTO cust_info(firstname, lastname, staddr, city, phone,      acct, ipaddr, hwaddr, cliid, bootfile)
        VALUES (:firstname, :lastname, :staddr, :city, :phone, :acct, :ipaddr, :hwaddr, :cliid, :bootfile)");

        $stmt->bindParam(':firstname', $_POST['firstname']);
        $stmt->bindParam(':lastname', $_POST['lastname']);
        $stmt->bindParam(':staddr', $_POST['staddr']);
        $stmt->bindParam(':city', $_POST['city']);
        $stmt->bindParam(':phone', $_POST['phone']);
        $stmt->bindParam(':acct', $_POST['acct']);
        $stmt->bindParam(':ipaddr', $_POST['ipaddr']);
        $stmt->bindParam(':hwaddr', $_POST['hwaddr']);
        $stmt->bindParam(':cliid', $_POST['cliid']);
        $stmt->bindParam(':bootfile', $_POST['bootfile']);

        $stmt->execute();
echo "done";
}
catch(PDOException $e)
{
echo 'failed: ' . $e->getMessage();
}


$bootfile = $_POST['bootfile'];
$cliid = $_POST['cliid'];
$ipaddr = $_POST['ipaddr'];
$hwaddr = $_POST['hwaddr'];

//Process data from form into cmts

$connection = fsockopen($router_ip, $port, $errno, $errstr, $timeout);

if(!$connection)
{
echo "Connection failed
";
exit();
}
else
{
fputs($connection, "$username");
fputs($connection, "$password");
// using term length 0 to keep  pause or more prompt from eating input
fputs($connection, "term length 0");
fputs($connection, "enable");
fputs($connection, "$password");
fputs($connection, "clear ip dhcp binding $ipaddr");
fputs($connection, "configure terminal");
fputs($connection, "ip dhcp pool $cliid");
fputs($connection, "host $ipaddr 255.255.255.0");
fputs($connection, "client-identifier $cliid");
fputs($connection, "bootfile $bootfile");
fputs($connection, "exit
");
fputs($connection, "exit
");
fputs($connection, "clear cable modem 172.16.16.248 reset
");
fputs($connection, "show cable modem remote | inc $hwaddr");
fputs($connection, "exit");
}
{
fgets($connection, 128);
}
stream_set_timeout($connection, 2);
$timeoutCount = 0;
while (!feof($connection))
{
$content = fgets($connection, 128);
echo $content."<br>";

}
$info = stream_get_meta_data($connection);
if ($info['timed_out'])
{
// If timeout of connection info has got a value, the router not returning a output.
$timeoutCount++;
// We want to count, how many times repeating.
}
 if ($timeoutCount >2)
 {
 // If repeating more than 2 times,
 break;
 // the connection terminating..
 }

 ?> 
  • 写回答

1条回答 默认 最新

  • dongzhangji4824 2013-05-17 03:36
    关注

    Brad gave me the hints I needed to come to the required results thanks again

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?